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

Where clause if true would not show at all

Have table where are two columns – client_id, content

every client have +- 50 content rows.

In WHERE i have this clause – where content NOT IN ('2','3','4')

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

In result shows same clients but without rows where are ‘2’,’3′,’4′. I need if found one client with content ‘2’,’3′,’4′ dont show this client completely

>Solution :

NOT IN only removes the rows with ‘2’,’3′ or ‘4’ in the content column.

Use NOT EXISTS:, the following query will return all client_id without ‘2’ ‘3’ or ‘4’ in the content column

SELECT DISTINCT client_id
FROM [your table] AS t
WHERE NOT EXISTS
  (SELECT 1 
   FROM [your table] 
   WHERE content in('2,'3','4') and [your table].client_id = t.client_id)
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