Mysql query help needed

Posted by Me-and-Coding on Stack Overflow See other posts from Stack Overflow or by Me-and-Coding
Published on 2010-06-01T10:27:35Z Indexed on 2010/06/01 10:33 UTC
Read the original article Hit count: 203

Filed under:
|
|
|

Hi,

i have two tables category and hotels where category.id should be equal to hotels.catid. Now how do i select 3 rows from each different category from the hotels table.

I have this query:

select h.* from hotels h inner join category c on h.catid = c.id
order by h.catid, h.hid

this selects all records, but i want to select three rows per different category so in all it should return 9 rows with 3 rows for each category.

If this can not be done in mysql, you could also suggest php code please.

Thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about sql