Reputation: 176
How do I do to select all or nothing using SQL, following the condition: If any tuple has a column with the value 1 it must return empty, however if all have the value 0 it return all tuples.
Upvotes: 2
Views: 104
Reputation: 726579
You can do it like this:
SELECT *
FROM MyTable
WHERE (SELECT COUNT(*) FROM MyTable t WHERE t.MyColumn=1)=0
The condition evaluates to true or false for all rows; if any row has 1
in it, no rows would be returned.
Upvotes: 3