A left associated SQL statement (MySQL)

Time:2020-9-19

Left associated SQL statement (MySQL)

SELECT *
FROM b 
    LEFT JOIN a
    ON a.trans_id=b.id
    AND a.target_col = 'date'
WHERE a.target_col IS NULL

explain:bandaIt’s a one to many relationship.

First look at the statement, found that the condition is botha.target_col='date'againa.target_col is nullThere seems to be a contradiction.
In fact, it is not. There is no problem with the statement. The analysis is as follows:

Sentence analysis:
1) FindbandaThe left associated data of;
2) BecausebandaIs a one to many relationship by adding conditionsa.target_col = 'date', restrict the association of this piece of data;
3) IfaNone of themtarget_col='date'A null record is associated;
4) Finally, it was approvedwhereCondition, filter outaandbIs related, andaNot configured intarget_col='date'Record of.

For example, there are data:
A left associated SQL statement (MySQL)

SELECT * FROM t1
LEFT JOIN t2
ON t1.name = t2.name
AND t2.type = 'b1'
WHERE t2.name IS NULL

Filter outt1Records ina3a3stayt2Notypebyb1Record of.

Recommended Today

Solutions to leetcode problems and knowledge points 1. Sum of two numbers

Title Link 1. Two Sum  difficulty: $/ color {00965e} {easy}$ Knowledge points 1. Hash (hash) function The classic hash function times33 is widely used, and the core algorithm is as follows: hash(i) = hash(i-1) * 33 + str[i] Laruence has an article about:Hash algorithm in PHP 2. Hash collision processing method 2.1 chain address method […]