Selecting distinct rows using join

7331

New Member
I have three table in database.Hostel\[code\]hostel_id int,hosteltype_id int,hostelname varchar(100)address varchar(800)\[/code\]hosteltypes\[code\]hosteltype_id int,Hosteltypename varchar(100)\[/code\]hostelrooms\[code\]room_id int,hostel_id int,Room_no int,available_beds intreserver int\[/code\]data in Hostel\[code\]1 1 hostel1 address12 1 hostel2 address23 2 hostel3 address34 2 hostel4 address4\[/code\]in hosteltype\[code\]1 boyshostel2 ladieshostel\[/code\]in hostelroom\[code\]1 1 101 4 42 1 102 4 23 1 103 4 44 2 100 4 45 2 101 4 16 3 101 4 4\[/code\]I can select rows using command.\[code\]select Hostel.hostel_id, Hostel.hostelname, Hostel.address, hosteltypes.Hosteltypename,from Hostel,hosteltypeswhere Hostel.hosteltype_id=hosteltypes.hosteltype_id and hostel_id = ( select distinct hostelrooms.hostel_id from hostelrooms where hostelrooms.hostel_id=Hostel.hostel_id and hostelrooms.hostelrooms>hostelrooms.reserver )i want data similar like 1 hostel1 address1 boyshostel 2 hostel2 address2 boyshostel\[/code\]how can a create sql command similar to above using join statement which returns specific hostelid,hostelname,hosteltype where the room available.
 
Top