Vote count: 0
I am looking for a way to return an ID only if NO rows hold a certain value
For example:
ID | Date
1 | 01/01/2001
1 | 02/02/2002
1 | 03/03/2003
If I want SQL to return the ID only if no dates are equal to 02/02/2002, how would I script that? I have tried and failed with the below:
select ID
from (example)
where date != 02/02/2002
The problem is that this still returns the ID - 1, as the first and last row do not equal 02/02/2002. What I am aiming for is no returned results because at least one row held the matching date.
I would need the script to completely skip the ID when there is a matching date in any row.
For clarity the below should return the ID when using the same 'select' as above because no dates are matching:
ID | Date
2 | 03/03/2003
2 | 04/04/2004
2 | 05/05/2005
SQL - Only return when no rows hold a value
Aucun commentaire:
Enregistrer un commentaire