我有两个表:
CREATE TABLE "status" (
"id" integer NOT NULL PRIMARY KEY,
"created_at" datetime NOT NULL,
"updated_at" datetime NOT NULL);
CREATE TABLE "device" (
"id" integer NOT NULL PRIMARY KEY,
"created_at" datetime NOT NULL,
"updated_at" datetime NOT NULL,
"last_status_object_id" integer REFERENCES "status" ("id"));
在表“设备”中,last_status_object_id引用status.id。
我想删除“ last_status_object_id”未引用的所有状态行。我似乎无法弄清楚如何做到这一点。谁能帮我吗?
DELETE
status
FROM
status
LEFT JOIN device ON (status.id = last_status_object_id)
WHERE
device.id IS NULL
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句