This query has gotten much more complex than I wanted, because the original source isn't quite what I expected. But what I'm trying to do is return all rows where CONCAT(colA, colB) match 5 or more times.
Here is a simplified version of where I started...
SELECT * FROM table
GROUP BY CONCAT(colA, colB)
HAVING COUNT(CONCAT(colA, colB)) >= 5
The problem here is that, instead of returning all of the matching results, it only returns one of them. So if there are 20 rows where CONCAT(colA, colB) matches, it only returns one of them when I would like to have all 20.
If I simply remove the "group by" line, it only returns 1 lines when I'm expected more like 250.
I tried using WHERE instead of HAVING, but of course that doesn't work because you use COUNT here. So I tried moving it to the SELECT, as so:
SELECT *, COUNT(CONCAT(colA, colB)) AS num FROM table
WHERE num >= 5
but then I get "unknown column 'nums'". And if I change it to HAVING instead of WHERE then, again, I only get 1 result.
Any suggestions on how to get all of the rows where CONCAT(colA, colB) matches more than X times?
I know that I could do it in PHP, but I'm trying to do it just in MySQL so that the client can use a copy-and-paste query without me having to write a script for them.