tags:

views:

32

answers:

5

Hi everybody , 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
A: 

select top 5 * from....

gillyb
it's not working i tried this
Mohan Sharma
A: 

You Can use

limit 5

Hiyasat
+2  A: 

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 
Chris Diver
Yes i want to display packages with the most bookings
Mohan Sharma
Did the SQL in the post work for you?
Chris Diver
Thank you very much Chris Diver visit me at www.google.com/profiles/mail2mohanpyare
Mohan Sharma
A: 
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.

zebediah49
there is error at limit keyword
Mohan Sharma
A: 
SELECT COUNT(trippackageID) AS tpi_c, trippackageid 
  FROM tbl_holiday_booking 
  GROUP BY trippackageID 
  ORDER BY tpi_c DESC 
  LIMIT 5
Piskvor