MySQL Left Join not returning null values for joined table

后端 未结 2 1646
你的背包
你的背包 2020-12-13 19:45

Please help me with the following MySQL query, which joins two tables (A and B):

SELECT * from A
left join B on A.sid = B.sid
where (rCode = 1 Or rCode = 2 O         


        
2条回答
  •  孤街浪徒
    2020-12-13 20:01

    You should not specify rYear in a WHERE clause. Those limit your results after the join. You should specify rYear in an ON clause to get back records with NULL from table B.

    SELECT * from A
    left join B 
    on A.sid = B.sid 
    AND (rYear = 2011 or rYear is null)
    where (rCode = 1 Or rCode = 2 Or rCode = 3 Or rCode = 5)
    

提交回复
热议问题