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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 inner joins

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-05-23 : 10:37:11
david writes "how would I do this?


I have 3 tables:

table1: ID
table2:ID, UPC
table3:UPC, NAME

there is a one to many relationship between table1.id and table2.id and also a one to many between table3.upc and table2.upc.


i need to look up the name in table3, based on the upc in table 2, which is based on the id in table 1.

for example if there is an id of 1 in table1, select all of the id's of 1 in table2, then take the corresponding upc's for id of 1. and lookup the names for the upc's in table3.


I hope you can help thanx."

M.E.
Aged Yak Warrior

539 Posts

Posted - 2002-05-23 : 10:53:59
I think

select ttt.name ,t.id
from table1 t inner join table2 tt on t.id = tt.id
inner join table3 ttt on tt.upc = ttt.upc
where t.id = 1


should show all the names (plz correct me if I'm wrong). Your result set may get rather large..

Edited by - M.E. on 05/23/2002 10:57:33
Go to Top of Page
   

- Advertisement -