我的问题如下:
我正在尝试使用WordNet MySQL,除了已经存在的视图外,试图添加另一个视图,例如:
CREATE OR REPLACE VIEW synsetsXsemlinksXsynsets AS
SELECT
linkid,s.synsetid AS ssynsetid
,s.definition AS sdefinition
,d.synsetid AS dsynsetid
,d.definition AS ddefinition
FROM synsets AS s
INNER JOIN
semlinks AS l ON s.synsetid = l.synset1id
INNER JOIN
synsets AS d ON l.synset2id = d.synsetid;
所以以该代码为参考,我试图做类似的事情:
CREATE VIEW graph AS
SELECT
l.linkid
,s.synsetid AS sssinsetid
,w.lemma AS swlemma
,s.definition AS sdefinition
,d.synsetid AS dsynsetid
,w.lemma AS dwlemma
,d.definition AS ddefinition
FROM synsets AS s
INNER JOIN
semlinks AS l ON s.synsetid = l.synset1id
INNER JOIN
synsets AS d ON l.synset2id = d.synsetid
INNER JOIN
lexlinks AS x ON l.synset1id = x.synset1id
AND l.synset2id = x.synset2id
INNER JOIN
words AS w ON w.wordid = x.word1id
AND x.word2id = w.wordid
为了得到:linkid | ssynsetid | swlemma | sdefition| dsynsetid | dwlemma | ddefition
。
但是它没有按预期工作。第一个给我285639行,而我的给我12行。我不确定问题出在哪里。有帮助吗?
将LEFT JOIN用于2个额外的表。
...
FROM synsets AS s
INNER JOIN
semlinks AS l ON s.synsetid = l.synset1id
INNER JOIN
synsets AS d ON l.synset2id = d.synsetid
LEFT JOIN
lexlinks AS x ON l.synset1id = x.synset1id
AND l.synset2id = x.synset2id
LEFT JOIN
words AS w ON w.wordid = x.word1id
AND x.word2id = w.wordid
因为如果使用INNER JOIN,那么它将过滤不匹配的那些。