MySQL Forums
Forum List  »  Optimizer & Parser

LEFT JOIN problem
Posted by: Steve Jordi
Date: July 17, 2006 07:13AM

Hi

I have a problem using a LEFT JOIN that doesn't return expected results.
It's probably something I do the wrong way.

There are two tables T1 and T2.
Each of them has columns named Genre and Species.
T2 serves as translations of Genre and Species from T1, using a Translated field.

What I want to achieve is to get the translation value for each lines I have on T1. When the translation doesn't exist, I expect it to be null.

What I have instead is nn lines. nn is #lines from T1 x #lines from T2
Adding a DISTINCT doesn't help.

SELECT T1.*, T2.Translated
FROM Table1 T1, Table2 T2
LEFT JOIN T2 ON ( T1.GENRE = T2.GENRE AND T1.ESPECE = T2.ESPECE )
WHERE T1.City LIKE 'BOLLIGEN%'

The where clause should return 2 instances only. One of them has a translation, the second doesn't.
So what I'd like to have is
#1, Genre, Species, Translated_value
#2, Genre, Species, null

Instead I get 10 results (2 from the Where clause, and I have 5 translations yet in T2: 2x5=10)

What is wrong in this select?
I tried to also add the same ON clause to the WHERE clause with an AND but then I get no records in return.

Thanks for any help.
Steve

Options: ReplyQuote


Subject
Views
Written By
Posted
LEFT JOIN problem
3397
July 17, 2006 07:13AM
1820
July 17, 2006 08:07AM
1772
July 17, 2006 09:30AM
1776
July 17, 2006 12:03PM
1706
July 17, 2006 10:23PM


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.