Home > Blockchain >  Where clause if true would not show at all
Where clause if true would not show at all

Time:07-08

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')

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

CodePudding user response:

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)
  • Related