Reputation: 4516
Here you can find how to check row existance:
SELECT EXISTS(SELECT 1 FROM table1 WHERE some_condition);
How to efficiently existance of multiple rows from table like:
SELECT EXISTS(SELECT 1 FROM table1 WHERE key = 0);
SELECT EXISTS(SELECT 1 FROM table1 WHERE key = 2);
from table:
key,username
0,foo
1,bar
2,boo
to return positive only if both rows (with key 0 and 2) was found?
Upvotes: 2
Views: 4554
Reputation: 204924
SELECT sum(`key` = 0) as key0_count,
sum(`key` = 2) as key2_count
FROM your_table
Upvotes: 1