Database Question

May 8, 2007
86
0
0
I want to use information from two tables to create a unique combination of data. Take this example using two tables, Foo and Boo. I want to combine both tables to generate a result set shown at the end. Thanks!

I am using SQL

Foo:

ID | Name |
1 | Joe
2 | Bob

Boo
cID | Person A | Person B
1 | 1 | 2


I want my result row to look something like
cID | A_ID | A_Name | B_ID | B_Name

so in the case of getting cID = 1 I want the row to be
1 | 1 | Joe | 2 | Bob
 

brandonb

Diamond Member
Oct 17, 2006
3,731
2
0
select boo.cid, p1.id, p1.name, p2.id, p2.name
from Boo
inner join foo AS p1 on boo.person_a = p1.id
inner join foo as p2 on boo.person_b = p2.id
 
May 8, 2007
86
0
0
awesome thank you! As a side note seeing as Im starting to push the limits of the w3 schools usefulness, do you have any resource recommendation for this kind of a thing. Part of my problem is that I do not know the database vocabulary very well.

Thanks!
 

brandonb

Diamond Member
Oct 17, 2006
3,731
2
0
I'm not sure.

I learned from coworkers after I got my first programming job (did not learn SQL in school as that was not taught back then). I did take a class about 6 years later from New Horizons and learned SQL programming then (after I already learned it) and thought that they did a terrific job.