1
刪除多行我有一個子查詢,因爲這:怎樣從一個表中的SQLite
SELECT INTER1.LID1 AS ILID1,INTER1.LID2 AS ILID2 FROM
(SELECT L1.ID1 AS LID1, L1.ID2 AS LID2 FROM Friend F1
INNER JOIN Likes L1
ON F1.ID1 = L1.ID1 AND F1.ID2 = L1.ID2) INTER1
LEFT JOIN Likes L2
ON (INTER1.LID1 = L2.ID2 AND INTER1.LID2 = L2.ID1)
WHERE (L2.ID1 IS NULL AND L2.ID2 IS NULL)
這樣做的輸出如下:
ID1 ID2
1641 1468
1911 1247
現在我要刪除這兩個從表中這些行LIKES其格式如下:
ID1 ID2
1689 1709
1709 1689
1782 1709
1911 1247
1247 1468
1641 1468
我試圖此使用以下查詢SQLite中來完成:
DELETE FROM Likes
WHERE EXISTS
(SELECT INTER1.LID1 AS ILID1,INTER1.LID2 AS ILID2 FROM
(SELECT L1.ID1 AS LID1, L1.ID2 AS LID2 FROM Friend F1
INNER JOIN Likes L1
ON F1.ID1 = L1.ID1 AND F1.ID2 = L1.ID2) INTER1
LEFT JOIN Likes L2
ON (INTER1.LID1 = L2.ID2 AND INTER1.LID2 = L2.ID1)
WHERE (L2.ID1 IS NULL AND L2.ID2 IS NULL));
但它不按預期工作,它不是隻刪除那些行。
然後我試着用INNER JOIN來解決這個問題,但是在DELETE函數中INNER JOIN的功能在SQLite中沒有。
我該如何做這項工作。
請幫助
我在線學習斯坦福大學的Lagunita SQL課程,似乎他們在指定之前使用SQLite版本來完成這項工作。是否有替代方案? –