SELECT * from A
SELECT * from B
These are the two-sheet bodies.
SELECT * from Left JOIN on a.ID=b.a_id;
statement One : SELECT*from leftjoins on a.id=and <3;
Statement two: SELECT*from leftjoins on a.id=WHERE <3;
The results of the two-statement query are different.
The keyword order for SQL queries is from, where, group by-> have->order by
The left join is in the from range so first on condition filter, then left JOIN
And where is filtered again after the result of the left join
Statement one (equivalent to select *from A left JOIN (SELECT * from B WHERE b.id < 3) b2 on a.id = b2.a_id;)
- Filter b.id<3 by on condition
- 1 query results with a LEFT join
Statement Two
- Left JOIN first
- Then filter again based on where conditions
Precautions for use:
- The filter criteria behind on are primarily for the associated table (the filter for the primary table does not apply)
- The filter criteria for the primary table should be placed behind the where and should not be placed behind
- If the query criteria query after the join connection should put the query conditions on the back; if you want to connect after the filter should put the condition behind where
- For association tables, you can do a subquery and join
The difference between on and where in MySQL after join