Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-10-2009, 09:35 AM   PM User | #1
coolguyraj
New Coder

 
Join Date: Nov 2005
Posts: 93
Thanks: 5
Thanked 0 Times in 0 Posts
coolguyraj is an unknown quantity at this point
Help need ed to write SQL query

I have two tables that are referenced:

1.Buildings

fields:buildingid,name

2.floors
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.
coolguyraj is offline   Reply With Quote
Old 03-10-2009, 09:47 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,056 Times in 4,025 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
It's called a JOIN. You really should read up on SQL enough to understand at least simple JOINs.

Code:
SELECT floorid, floors.name, buildings.name
FROM floors, buildings
WHERE floors.buildingID = buildings.buildingID
ORDER BY floorid
That can also be written as:
Code:
SELECT floorid, floors.name, buildings.name
FROM floors INNER JOIN buildings
ON floors.buildingID = buildings.buildingID
ORDER BY floorid
Please tell me this is not homework.
Old Pedant is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:37 PM.


Advertisement
Log in to turn off these ads.