我有2张桌子
表1:
+-------------------------+--------+
| Playername | Gender |
+-------------------------+--------+
| Kendall dddddd | Female |
| Ivy xxxxxxxx | Female |
| Carson xxxxxxx | Female |
+-------------------------+--------+
表2:
+----------------+----------+
| Playername | EvalYear |
+----------------+----------+
| Kendall dddddd | 2014 |
| Carson xxxxxxx | 2013 |
+----------------+----------+
查询
SELECT table1.Playername, table1.Gender, table2.EvalYear
FROM table1
LEFT JOIN table2 ON table1.Playername = table2.PlayerName
where table2.EvalYear is Null and table2.EvalYear != '2014'
我需要查询返回 Ivy 和 Carson 名称。
答案 0 :(得分:1)
在执行LEFT JOIN
时,您应该在ON
子句中的第二个表中放置必须匹配的条件,而不是WHERE
子句。由于您返回的行与年份不匹配,因此您需要更改测试的意义。
SELECT table1.Playername, table1.Gender, table2.EvalYear
FROM table1
LEFT JOIN table2 ON table1.Playername = table2.PlayerName AND table2.EvalYear = 2014
结果:
+----------------+--------+----------+
| Playername | Gender | EvalYear |
+----------------+--------+----------+
| Kendall dddddd | Female | 2014 |
| Ivy xxxxxxxx | Female | NULL |
| Carson xxxxxxx | Female | NULL |
+----------------+--------+----------+
答案 1 :(得分:0)
<强>查询强>
SELECT table1.Playername, table1.Gender, table2.EvalYear
FROM table1
LEFT JOIN table2 ON table1.Playername = table2.PlayerName
where PlayerEvals.EvalYear is Null or PlayerEvals !='2014'