The work has the following SQL, for a.id = ' ABCDEFG ', left join B and C two tables, to find additional information. Even if there are no records in B and C that meet the criteria, the final result is definitely not empty. Because a.id = ' ABCDEFG ' is present.
SELECT ****** fromTableA A Left JOINTableB B onb.deleted= '0' anda.deleted= '0' andB.fid=a.id Left JOINTableC C onB.xxxid=C.id andc.deleted= '0'WHEREa.ID='ABCDEFG'
The first thing I'm writing is this: put b.deleted = ' 0 ' behind, which results in NULL, because: if you put and b.deleted = ' 0 ' At the end, it is the result of the left join filtered,
At this point it is possible to cause the result to be null. (Consider this: the B and C tables do not have a successful record with a connection, if you use the SQL above, will result, using this SQL, will be null)
SELECT ****** fromTableA A Left JOINTableB B on anda.deleted= '0' andB.fid=a.id Left JOINTableC C onB.xxxid=C.id andc.deleted= '0'WHEREa.ID='ABCDEFG' andb.deleted= '0'
Above this problem is encountered in the work, accidentally wasted a lot of time to fix, SQL Master bad!
MySQL learning two about left connection