如何在mysql查询中过滤非空值?

时间:2014-11-30 23:26:39

标签: mysql

我有以下mysql查询。联接仅在FK上完成。

select le.lexicalentryid,  def.senseid, def.definitionid, frwf.writtenForm, trdef.writtentext, frwf.wordformid, frwf.phoneticForm, le.partofspeech, le.lexiconid
from formrepresentation_wordform frwf 
left join wordform wf on wf.wordformid = frwf.wordformid
left join lexicalentry le on le.lexicalentryid = wf.lexicalentryid
left join sense se on se.lexicalentryid = le.lexicalentryid
left join definition def on def.senseid = se.senseid
left join textrepresentation_definition trdef on trdef.definitionid = def.definitionid
where frwf.languageidentifier like '%deu%'

我得到以下结果(我只显示前4个)

我想摆脱空值。它们出现是因为同一definitionid我有一个书面形式。当发生这种情况时,我知道我必须从其他表中删除丢失的单词,所以现在,我必须清除空值。

我尝试添加到where子句frwf.writtenForm is not null,但没有成功(所有的writeform列都变成空白)

2 个答案:

答案 0 :(得分:1)

我设法创建了查询:

SELECT frl.writtenForm, frl.languageIdentifier, le.partOfSpeech, wf.idx, frw.phoneticForm, se._index, trd.writtenText
FROM FormRepresentation_Lemma frl
JOIN LexicalEntry le ON (frl.lemmaId = le.lemmaId)
JOIN WordForm wf ON (le.lexicalEntryId = wf.lexicalEntryId)
JOIN FormRepresentation_WordForm frw ON (frw.wordFormId = wf.wordFormId)
JOIN Sense se ON (le.lexicalEntryId = se.lexicalEntryId)
JOIN Definition de ON (se.senseId = de.senseId)
JOIN TextRepresentation_Definition trd ON (de.definitionId = trd.definitionId)
WHERE frl.languageidentifier like '%deu%'

这个表我没有考虑FormRepresentation_Lemma包含空值的链接条目

答案 1 :(得分:0)

你需要一个内部联接

select le.lexicalentryid,  def.senseid, def.definitionid, frwf.writtenForm, trdef.writtentext, frwf.wordformid, frwf.phoneticForm, le.partofspeech, le.lexiconid
from formrepresentation_wordform frwf 
inner join wordform wf on wf.wordformid = frwf.wordformid
left join lexicalentry le on le.lexicalentryid = wf.lexicalentryid
left join sense se on se.lexicalentryid = le.lexicalentryid
left join definition def on def.senseid = se.senseid
left join textrepresentation_definition trdef on trdef.definitionid = def.definitionid
where frwf.languageidentifier like '%deu%'

也可能是其他人也加入了。内部联接声明两个表必须具有要获取的匹配条目。