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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 tables 2 relations??? 1

Status
Not open for further replies.

elck

Programmer
Apr 19, 2004
176
NL
Table 1: pong

user1id
user2id
title

Table 2: users
id
name

SELECT title,name,name FROM pong JOIN users ON user1id=id,user2id=id

I need two names for 1 record in 'pong'
How can I do that please?
 
SELECT * FROM `pong` JOIN `users` ON user1=record

SELECT name FROM `pong` JOIN `users` ON user2=record

Ok this is what I do now, it works, just as a matter of interest, could it have been done in 1 query?

 
How about:
[tt]
SELECT title,u1.name,u2.name
FROM
pong
LEFT JOIN users u1 ON user1id=u1.id
LEFT JOIN users u2 ON user2id=u2.id
[/tt]



-----
ALTER world DROP injustice, ADD peace;
 
Great!

I just had to make that:

SELECT title,u1.name,u2.name as name2
FROM
pong
LEFT JOIN users u1 ON user1id=u1.id
LEFT JOIN users u2 ON user2id=u2.id

Because PHP assoc_array didn't recognise it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top