mysql - Order By then Group? -


i have 2 tables, first, hotel_info has fields such as(hotel_id,hotel_name,location) , second table rooms, has room information such as(room_id,room_name,hotel_id,rate,description). want query returns minimum room rate hotel , information hotel hotel_info table. far have query working not returning minimum room rate.

select a.hotel_id,a.hotel_name ,a.location, b.rate hotel_info  left join rooms b on b.hotel_id=a.hotel_id  group hotel_id 

how minimum room rate per hotel?

you can use mysql function min() such as

select a.hotel_id, min(b.rate)  hotel_info  left join rooms b on b.hotel_id = a.hotel_id  group a.hotel_id; 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -