Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Help need ed to write SQL query
03-10-2009, 09:35 AM #1
- Join Date
- Nov 2005
- Thanked 0 Times in 0 Posts
Help need ed to write SQL query
I have two tables that are referenced:
fields:floorId,name,BuildingId(linked to buildings table using buildingId)
Curently if i select all the details from floors table it will give all the details.
But i want Building name to be displayed instead of buildingId.
Output should look like:
floorid name buildingname
1 first xyz building
2 second xyz building
3 third xyz building
what is the SQL query required to get the above output.
03-10-2009, 09:47 AM #2
It's called a JOIN. You really should read up on SQL enough to understand at least simple JOINs.
That can also be written as:Code:SELECT floorid, floors.name, buildings.name FROM floors, buildings WHERE floors.buildingID = buildings.buildingID ORDER BY floorid
Please tell me this is not homework.Code:SELECT floorid, floors.name, buildings.name FROM floors INNER JOIN buildings ON floors.buildingID = buildings.buildingID ORDER BY floorid