Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 joining three tables

Author  Topic 

kurious_mind
Starting Member

3 Posts

Posted - 2007-07-19 : 11:07:20
OK this is probably a really simple question, but I need to join three tables and I dont understand which types of "JOIN"s to use or how to lay it all out. Just as an example, this is what i want to do:

(table_name | field1, field2,)

kids_tbl | id, first_name, hair, eyes

hair_tbl | id, hair_color

eye_tbl | id, eye_color


So I want to replace the hair and eye color in the kids_tbl (which are numbers corresponding with the ids in the other tables) with the actual word from the correct table.

I have been reading up on this but it just isn't making sense to me.


khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-19 : 11:10:45
use INNER JOIN


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

kurious_mind
Starting Member

3 Posts

Posted - 2007-07-19 : 11:32:41
OK, thank you!

But when I put it together I get an error. I can join two tables but when I add the third it tells me I am missing an operator. Here what I have (keeping with the above example)

SELECT *
FROM kids_tbl k INNER JOIN hair_tbl h ON k.hair = h.id
INNER JOIN eye_tbl e ON k.eyes = e.id

any help?
Go to Top of Page

kurious_mind
Starting Member

3 Posts

Posted - 2007-07-19 : 14:16:56
I figured it out. For anyone else who reads this... I have a access database and to join three or more table you need to use parentheses, like so...

SELECT *
FROM ((kids_tbl k INNER JOIN hair_tbl h ON k.hair = h.id)
INNER JOIN eye_tbl e ON k.eyes = e.id)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-19 : 15:55:10
MS Access queries should be posted in proper forum.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -