Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Find Unique Rows from given data

I am trying to find out unique rows from the given data

In my case I am storing buy sell of the stock in stock table. So same client can buy sell same stock.

So ask is to just fetch stocks which are only BUY and not SELL by any other client.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is the sqlFiddle link where I have shared table structure and query I tried
http://sqlfiddle.com/#!9/df117d/2

I am expecting result as –

STOCKB
STOCKD
STOCKE

>Solution :

You can do:

SELECT DISTINCT s.symbol 
FROM bulk s 
WHERE s.buy_sell='BUY' AND 'SELL' not in (
  SELECT a.buy_sell
  FROM bulk a
  WHERE a.symbol = s.symbol AND a.buy_sell='SELL'
)

See SQLFiddle

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading