MySQL Forums
Forum List  »  Newbie

Re: query problem joining 2 tables with where clause only filtering one table
Posted by: Felix Geerinckx
Date: August 09, 2005 01:18AM

Tony Elmiger wrote:

> Select clients.*, contacts.*
> FROM clients LEFT JOIN contacts ON
> clients.client_id = contacts.contact_id
> Where contacts.hide = 0
>
>
> The problem I have with the above query is that if I have 1 client record and 1 contact record with
> the hide field = 1 the client record is not displayed anymore either.

Move the condition in the WHERE clause to the ON clause:

Select clients.*, contacts.*
FROM clients
LEFT JOIN contacts ON clients.client_id = contacts.contact_id AND contacts.hide = 0

--
felix
Please use BBCode to format your messages in this forum.

Options: ReplyQuote


Subject
Written By
Posted
Re: query problem joining 2 tables with where clause only filtering one table
August 09, 2005 01:18AM


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.