If there is no matching record for the right table in the ON or USING part in a LEFT JOIN, a row with all columns set to NULL is used for the right table. You can use this fact to find records in a table that have no counterpart in another table:
mysql> SELECT table1.* FROM table1
-> LEFT JOIN table2 ON table1.id=table2.id
-> WHERE table2.id IS NULL;
This example finds all rows in table1 with an id value that is not present in table2 (that is, all rows in table1 with no corresponding row in table2). This assumes that table2.id is declared NOT NULL, of course.
Так вот? существует ли какой либо трюк, позволяющий вместо NULL подставлять что нибудь другое (например, 0 или 'undefined')? https://academ.club/html/emoticons/stena.gif
Из мануала:
mysql> SELECT table1.* FROM table1
-> LEFT JOIN table2 ON table1.id=table2.id
-> WHERE table2.id IS NULL;
This example finds all rows in table1 with an id value that is not present in table2 (that is, all rows in table1 with no corresponding row in table2). This assumes that table2.id is declared NOT NULL, of course.
Так вот? существует ли какой либо трюк, позволяющий вместо NULL подставлять что нибудь другое (например, 0 или 'undefined')? https://academ.club/html/emoticons/stena.gif