I have the following SQL query and the result of the query is shown below. How do i select multiple minimum values based on cnt column?
SELECT a.id , COUNT(a.id) cnt
from table1 a
where a.id in (SELECT id from table2 WHERE name = 'abc')
GROUP BY a.id
Output of the above query
"id" "cnt"
1003 3
1008 1
1011 2
1017 1
I would like the output to be
"id" "cnt"
1008 1
1017 1
Any help is appreciated. Thank you.
2
Answers
You can using having to check
Check out this db fiddle
You could use a Having to get the Min count.