Pretty much as the title says, that was the simplest way I could explain it. To elaborate...
I first need to find the value of column c that has been duplicated the most times (mostDuplicated), and then SELECT * FROM t WHERE c=mostDuplicated
To go on about it further...
Here's my data:
SELECT * FROM t
a, b, c
- - -
1, 1, 1
2, 2, 1
3, 3, 1
4, 4, 2
5, 5, 3
So ignore the values in columns a & b completely, just concentrate on column c. I need to find the most duplicated value in column c (which is 1), and then SELECT only these records WHERE c=1. I want to do this in a single query if possible.
Do a "group by" query to count the number of unique values of c
, order it descending and select only the top row. Then use the output as a subquery to select rows with that particular value of c
:
SELECT * FROM t WHERE c = (SELECT c FROM t GROUP BY c ORDER BY COUNT(*) DESC LIMIT 1)
SELECT c FROM t GROUP BY c ORDER BY count(*) DESC LIMIT 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With