2009-11-19 4 views
2

Je tente d'effectuer une jointure à gauche avec une condition. Dites ceci est ma table:Left Join Problème

a  b  c 
------------------------- 
1  1  NULL 
3  3  something 

et ma requête est

select * from x left join y on x.a = y.b 

Le problème est que je ne veux pas c d'être "quelque chose" donc quand j'ajouter

select * from x left join y on x.a = y.b where y.c <> 'something' 

il affiche 0 lignes. il devrait effectivement afficher

a  b  c 
------------------------- 
1  1  NULL 

Répondre

2
select * 
from x left join y on x.a = y.b 
WHERE y.c IS NULL OR y.c <> 'something' 
1

Je pense que vous MENT:


SELECT * 
FROM x 
LEFT JOIN y ON x.a = y.b 
WHERE y.c <> 'something' 
+0

oui, désolé réparé –

0

Vieille réponse, mais normalement pour cette solution la plus simple est de mettre le contrôle dans la clause ON: -

SELECT * 
FROM x 
LEFT OUTER JOIN y 
ONx.a = y.b 
AND y.c <> 'something'