2

我不知道如何删除属于特定文件的单词。我正在尝试删除属于 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;
4

2 回答 2

2

您是否尝试仅从“文件”表中删除该特定文件。如果是,请尝试以下代码,

DELETE
FROM files f, fileword fw, words w
WHERE f.fileId = 42
and f.fileId = fw.wordId 
and f.fileId = w.wordId;
于 2013-10-23T05:06:57.660 回答
2

尝试这个:

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
于 2013-10-23T05:08:34.347 回答