我不知道如何删除属于特定文件的单词。我正在尝试删除属于fileId为42的文件的单词。有人认为他们能帮我吗?

Table file
fileId - Primary Key
fileName - Normal column.
fileUrl - Normal column.

Table fileWord
fileId, wordId - Primary Key, Foreign Key
count - Normal column.

Table word
wordId - Primary Key
word - Normal Column

我的SQL:
DELETE words
FROM files f, fileword fw, words w
WHERE 42 = fw.fileId AND fw.wordId = w.wordId;

最佳答案

试试这个:

DELETE f FROM files as f
inner join fileword as fw on f.fileId = fw.wordId
inner join words as w on f.fileId = w.wordId
WHERE f.fileId = 42

如果要从单词表中删除单词,则
DELETE w FROM files as f
inner join fileword as fw on f.fileId = fw.wordId
inner join words as w on fw.wordId = w.wordId
WHERE f.fileId = 42

09-26 03:38