Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select with two joins to one table

Status
Not open for further replies.

tonvaneck

IS-IT--Management
Jan 19, 2004
19
NL
Dear sql users,

We are busy to create a simple select statement. In this select statement there are two joins to one tabel.

TblReaders
Name1_id name2_id
1 2
3 4


TblNames
Id Names
1 John
2 Mary
3 Edward
4 NN


The query must create next result:

Name1 Name2
John Mary
Edward NN

Knows someone a solution?

Thanks for reading.

Ton.
 
Try this:

Code:
Select Names1.Names, Names2.Names From TblReaders
Inner Join TblNames Names1 On Names1.ID = TblReaders.Name1_id
Inner Join TblNames Names2 On Names2.ID = TblReaders.Name2_id
 
What doesn't work? Are you getting an error? Is the data incorrect?
 
hello juice05,

we are using sqlserver 2000

The query gives an syntax error in the two joins

Ton.
 
tonvaneck, read your manual about alias and post in a sql server forum for sql 2000 issue.
 
Try this:

Code:
Select Names1.Names First, Names2.Names Second From TblReaders
Inner Join TblNames Names1 On Names1.ID = TblReaders.Name1_id
Inner Join TblNames Names2 On Names2.ID = TblReaders.Name2_id

If you get an error, please give me the entire error message.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top