Skip to content
Advertisement

sql: exclude rows if at least one row within it isn’t in the list

I have the following simple table

COL1 COL2 COL3
U1 L1 X
U1 L5 X
U2 L2 X
U3 L2 X
U4 L4 X
U4 L6 X
U5 L7 X

when I execute the statement

Result:

My desired result is

The U1 and U4 should be filtered out because one of their COL2 contains an element which is not in the list.

Is it possible to achieve it in a SQL statement?

I appreciate any help!

Advertisement

Answer

A full example of how to achieve what you want using a simple aggregate function:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement