user1497398
user1497398

Reputation: 27

Sql filtering id's

I want to create a sql query that lets me make a top 5 of the most used ids in my table. My table has these columns:

reservationid
costumerid
roomid
hotelid

I'm trying to get a top 5 of the most used hotel ids.

I thought I had to use the count function but that doesn't seem to work. It just counts all the hotelids and doesn't see the difference between the id's

select count(hotelid) from reservation;

Can someone help me push me in the right direction?

Thanks in advance!

Upvotes: 1

Views: 59

Answers (1)

Tucker
Tucker

Reputation: 7362

SELECT COUNT(`hotelid`) AS `freq`, `hotelid` 
        FROM `reservation` 
    GROUP BY `hotelid` 
    ORDER BY `freq` DESC LIMIT 5 ;

Upvotes: 2

Related Questions