Spartaok
Spartaok

Reputation: 199

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?

Upvotes: 1

Views: 231

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269553

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.

Upvotes: 2

Related Questions