0

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  |
+-----+-----+-----+
Community
  • 1
  • 1
achiash
  • 1,692
  • 2
  • 12
  • 14

2 Answers2

1

The HAVING clause

 SELECT ...
 FROM ...
 WHERE ...
 GROUP BY whatever
 HAVING count(*) <3
podiluska
  • 50,950
  • 7
  • 98
  • 104
1

Just add the condition in the HAVING clause

SELECT colName, COUNT(*)
FROM tableName
GROUP BY colName
HAVING COUNT(*) < 3
John Woo
  • 258,903
  • 69
  • 498
  • 492