Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

anybody please how do you find max of a count

Status
Not open for further replies.

room24

Programmer
Dec 28, 2003
83
JM
Name Null? Type
----------------------------------------- -------- ----------------------------
ART_ID NOT NULL float
MUS_ID NOT NULL float
SHORT_DESC VARCHAR(80)

in the table above this query select art_id, count(*) from works_with group by art_id; results in..

ART_ID COUNT(*)
------ ----------
2196 3
2197 2
2198 2
2199 2
2201 2
2202 2
2203 2
2204 2
2205 2
2206 2
2207 2

ART_ID COUNT(*)
------ ----------
2208 2
2209 2
2301 2
2302 2

how can i get the art_id which has the max of count(*) (in this case this would be art_id = 2196)
 
SELECT * FROM (SELECT art_id, count(*) AS cnt FROM works_with GROUP BY art_id) AS tmp ORDER BY cnt DESC LIMIT 1

I can't think now for if there is a better way, but this one works
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top