Reputation: 1682
regarding that question: How to count rows that have the same values in two columns (SQL)?
is there a way to return only the rows where the count is < 3?
+-----+-----+-----+
| A | B |count|
+=====+=====+=====+
| 1 | 3 | 2 |
+-----+-----+-----+
| 4 | 2 | 1 |
+-----+-----+-----+
Upvotes: 0
Views: 229
Reputation: 263803
Just add the condition in the HAVING
clause
SELECT colName, COUNT(*)
FROM tableName
GROUP BY colName
HAVING COUNT(*) < 3
Upvotes: 1
Reputation: 51504
The HAVING
clause
SELECT ...
FROM ...
WHERE ...
GROUP BY whatever
HAVING count(*) <3
Upvotes: 1