0

How can I display ONLY id 4 and 2 because they have the highest count?

SELECT id, count(*) FROM followers GROUP BY id ORDER BY 2 DESC;

id count
4  4
2  4
1  3
3  2

expected outout

id count
4  4
2  4

1 Answer 1

1

You could use a Common Table Expression (CTE) like below:

 WITH counts AS ( 
 SELECT id, count(*) AS cnt FROM followers GROUP BY id)
 SELECT * FROM counts where cnt = (select MAX(cnt) from counts)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.