Skip navigation links

MySQL Forums :: MySQL Query Browser :: LEFT JOIN did not differentiate the same table with different names


Advanced Search

LEFT JOIN did not differentiate the same table with different names
Posted by: noctua don ()
Date: February 03, 2012 08:58AM

hi

I have some problem with the join funtionality.

Here are some of my tables:

Table: client
int id_client PRIMARY KEY

Table: client_has_phonenumber
int id_client
int id_phonenumber
composed primary key

Table: phonenumber
int id_phonenumber PRIMARY KEY
char(45) type PRIMARY KEY


Every client has two numbers: his private, and his mobile number. Now I want query both of them. to connect them with the client I have the table client_has_phonenumber with both ID's of the other tables as a composed primary key.

Here is my Query, but the problem with it is that he did not differentiate the phonenumber tables. i got always the same number and not two different ones.

Hope some one can help me.


SELECT *
FROM `client`
LEFT JOIN (
`client_has_phonenumber`,
`phonenumber` AS `phonenumber_private`,
`phonenumber` AS `phonenumber_mobile`,
)
ON client.id_client = client_has_phonenumber.id_client
AND client_has_phonenumber.id_phonenumber = phonenumber_private.id_phonenumber
AND client.id_client = client_has_phonenumber.id_client
AND client_has_phonenumber.id_phonenumber = phonenumber_day.id_phonenumber
WHERE case.id_case = 2
AND phonenumber_private.type = 'private'
AND phonenumber_mobile.type = 'mobile'



Edited 1 time(s). Last edit at 02/03/2012 02:55AM by noctua don.

Options: ReplyQuote


Subject Written By Posted
LEFT JOIN did not differentiate the same table with different names noctua don 02/03/2012 08:58AM


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.