Reputation: 165
I want to retrieve top 5 rows returned by this query. How to do this
select COUNT(trippackageID), trippackageid
from tbl_holiday_booking
group by trippackageID
Upvotes: 1
Views: 466
Reputation: 92792
SELECT COUNT(trippackageID) AS tpi_c, trippackageid
FROM tbl_holiday_booking
GROUP BY trippackageID
ORDER BY tpi_c DESC
LIMIT 5
Upvotes: 0
Reputation: 7611
select COUNT(trippackageID) as cnt, trippackageid from tbl_holiday_booking group by trippackageID ORDER BY cnt DESC LIMIT 0,5
Assuming you do, in fact, want to order by the count, descending (large to small). LIMIT 0,5 starts at row 0, and returns the next 5 rows.
Upvotes: 0
Reputation: 19842
You are not specifying the order, do you want the package with the most bookings or the least?
SELECT TOP 5 COUNT(truppackageID) Num, trippackageid FROM tbl_holiday_booking GROUP BY trippackageID ORDER BY Num DESC
Upvotes: 2