且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL左联接?

更新时间:2022-02-21 21:58:34

将用户名条件从WHERE子句移动到ON子句.

Move the username condition from the WHERE clause to the ON clause.

SELECT *
FROM cars
LEFT JOIN carLog
  ON cars.id=carLog.car
     AND carLog.username='Juddling'

在JOIN已经完成时,将应用WHERE子句.这意味着,它将丢弃LEFT JOIN添加的NULL行.

The WHERE clause is applied when the JOIN is already completed. This means, it will discard the NULL rows that the LEFT JOIN added.