问题
This is valid syntax on Microsoft SQL Server's T-SQL, but not in SQLite, is there an alternative syntax that does the same in SQLite?
DELETE FROM something
FROM something
INNER JOIN combinations ON something.field1=combinations.field1
AND something.field2=combinations.field2
--optionally more criteria and/or more joins
WHERE combinations.field3=1234
--or anything really, just to show some criteria could be applied here also
回答1:
In the general case, move the entire join into a subquery that looks up the primary keys of the rows to be deleted:
DELETE FROM something
WHERE id IN (SELECT something.id
FROM something
JOIN combinations ON something.field1=combinations.field1
AND something.field2=combinations.field2
WHERE combinations.something=1234)
If you have a composite primary key, you can use the rowid instead:
DELETE FROM something
WHERE rowid IN (SELECT something.rowid
FROM something
JOIN combinations ON something.field1=combinations.field1
AND something.field2=combinations.field2
WHERE combinations.something=1234)
If you have a composite primary key and you created the table as a WITHOUT ROWID table, you have to rewrite the join as a correlated subquery:
DELETE FROM something
WHERE EXISTS (SELECT 1
FROM combinations
WHERE field1 = something.field1
AND field2 = something.field2
AND field3 = 1234)
回答2:
Here you have an alternative:
DELETE FROM slave
where slave.master_id in (select master.id from master where master.something=1234)
来源:https://stackoverflow.com/questions/24067581/does-sqlite-support-delete-from-from