我有一个脑死亡的时刻......我有两个表格描述:
CREATE TABLE table_a ( id INTEGER PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255) NOT NULL UNIQUE (name)) CREATE TABLE table_b ( id INTEGER PRIMARY KEY AUTO_INCREMENT, a_key INTEGER NOT NULL, other_stuff VARCHAR(255) NOT NULL, FOREIGN KEY(a_key) REFERENCES table_a(id) ON DELETE CASCADE)
如何从table_a中选择table_b.a_key中没有条目的所有行?
SELECT table_a.* FROM table_a LEFT JOIN table_b ON table_a.id = table_b.a_key WHERE table_b.id IS NULL