Today to do a stored procedure, the function is to query everyone's score, some people do not give 0 points, it is obvious here with the left outer connection is no problem,
But after the connection has a time-based filtering function, so I added the where condition to judge, this time did not think of things happen, the role of Left outer connection does not
, and become the same as the internal connection query, no score of the people will not be queried out, and then asked the person to think about it, left outer connection query is a result set, also
Can be said to be a temporary table, plus where after the query out based on the filter once, naturally there is no condition of the record. The correct treatment should be to put on the back of the
where you switch to and to query when you connect, here's an example.
There are two tables below
1.stu Student Table
2.score score Table
Compare the following two different types of queries!
SELECT S. ' Name ', Ifnull (c. ' Score ', 0) as score from Stu S left joins score C on S. ' id ' = c. ' stu_id ' WHERE score > 50
This is the first query out the result set and then filter, naturally no less than 50 records
SELECT S. ' Name ', Ifnull (c. ' Score ', 0) as score from Stu S left joins score C on S. ' id ' = c. ' stu_id ' and score > 50
This is the first filter query out of the result set, you can query out all the records
Questions about the left join that don't work when you encounter where