mysql left join

当ctable中没与materials表中匹配的记录时,修改materials的up为1

1
2
UPDATE materials m left join ctable c on m.Id = c.Id SET m.up = 1
where c.Id is NULL;

删除table2中table1_id为空的记录

1
2
3
4
DELETE t2
FROM table1 t1
LEFT JOIN table2 t2 ON t1.id = t2.table1_id
WHERE t2.table1_id IS NULL