Maria1995
Maria1995

Reputation: 491

SQL query for retrieving the combination of columns with the highest number of apparitions

I am trying to create a SQL query for retrieving the combination of columns from a table which have the highest number of occurrences for identical values. Example:

id  a   b   c   d   e
1   0   3   5   7   1
2   0   3   5   7   2
3   0   3   5   7   3
4   1   4   6   8   2
5   1   4   6   8   3
6   2   2   2   2   5

output: 0 3 5 7

Upvotes: 0

Views: 38

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269543

If you just want the values from the first four columns that are most common:

selet a, b, c, d
from t
group by a, b, c, d
order by count(*) desc
limit 1;

Upvotes: 2

Related Questions