Skip to content
Advertisement

How to check if a table contains a specific number of rows?

I have this query:

SELECT (COUNT(*) = SUM(status in (3, 5)) ) AS result 
FROM `match` WHERE round_id = 15

this essentially check if the table match have all the items with a status 3 or 5 for the round 15. This works, but I actually want add another condition, in particular if the result is true I want check that all the records of that table with round_id = 15 are 20. How can I perform this?

Advertisement

Answer

Is this what you want?

SELECT (COUNT(*) = SUM(status in (3, 5)) AND COUNT(*) = 20) AS result 
FROM `match`
WHERE round_id = 15;

This checks that there are 20 rows that match the conditions.

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