MySQL Forums
Forum List  »  Newbie

Re: new to joins
Posted by: Ramalingam Chelliah
Date: September 01, 2004 10:52PM

Hi,
Sorry the order of JOIN was given wrongly....

Tables should be joined in this order
contacts ,events ,contacts

( Xeon's reply would give you primary /secondary ID
And for Xeon , this is a hint...
INNER JOIN -order not important
LEFT/RIGHT JOINs ORDER is important
)

Now ,

SELECT X.lastname,Y.lastname,Z.eventcode
FROM
CONTACTS as X
LEFT OUTER JOIN
EVENTS as Z
ON X.contactId = Z.primary_contactId
LEFT OUTER JOIN
CONTACTS as Y
ON Y.contactId= Z.secondary_contactId;

If you don't want to see Null ADD WHERE Condition ...
or A simple INNER JOIN....
(order not important)

SELECT X.lastname,Y.lastname,Z.eventcode
FROM
EVENTS as Z,CONTACTS as X,CONTACTS as Y
WHERE X.contactId=Z.primary_contactId
AND
Y.contactId=Z.secondary_contactId ;


Regards,
Ram.







We Learn the Most When we have to Invent

Options: ReplyQuote


Subject
Written By
Posted
August 30, 2004 10:03PM
August 31, 2004 02:36AM
August 31, 2004 04:36AM
August 31, 2004 09:36AM
September 01, 2004 01:46PM
Re: new to joins
September 01, 2004 10:52PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.