Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 左连接问题_Mysql - Fatal编程技术网

Mysql 左连接问题

Mysql 左连接问题,mysql,Mysql,我试图做一个左连接和一个条件。假设这是我的桌子: a b c ------------------------- 1 1 NULL 3 3 something 我的问题是 select * from x left join y on x.a = y.b 问题是我不希望c是“某物”,所以当我添加 select * from x left join y on x.a = y.b where y.c <> 'something' 我想你

我试图做一个左连接和一个条件。假设这是我的桌子:

a     b     c
-------------------------
1     1     NULL
3     3     something
我的问题是

select * from x left join y on x.a = y.b
问题是我不希望c是“某物”,所以当我添加

select * from x left join y on x.a = y.b where y.c <> 'something'
我想你应该:


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

挑选*
从x
x.a=y.b上的左连接y
y.c“某物”在哪里
选择*
从x向左,在x.a=y.b上连接y
其中y.c为NULL或y.c“某物”

旧的回复,但通常最简单的解决方案是在ON子句中加入检查:-

SELECT * 
FROM x 
LEFT OUTER JOIN y 
ONx.a = y.b 
AND y.c <> 'something'
选择*
从x
左外连接y
ONx.a=y.b
还有y.c.“什么”
select * 
from x left join y on x.a = y.b 
WHERE y.c IS NULL OR y.c <> 'something'
SELECT * 
FROM x 
LEFT OUTER JOIN y 
ONx.a = y.b 
AND y.c <> 'something'