Why MySQL's LEFT JOIN is returning “NULL” records when with WHERE clause?

前端 未结 4 598
野性不改
野性不改 2021-02-01 09:39

Today I\'ve tried some more complex MySQL queries and I\'ve noticed that MySQL\'s LEFT JOIN is not working with WHERE clause. I mean, it does return some records but it does not

4条回答
  •  后悔当初
    2021-02-01 10:12

    "The LEFT JOIN keyword returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side when there is no match."

    The above quote is from w3schools.com

    However, when you place a WHERE clause on a LEFT JOIN, SQL now treats that as an INNER JOIN and:

    "The INNER JOIN keyword selects all rows from both tables as long as there is a match between the columns in both tables."

    Also quoted from w3schools.com

    TLDR;

    The introduction of the WHERE clause to a LEFT OUTER JOIN gives the join the behavior of an INNER JOIN

提交回复
热议问题