i have a query where it searches for a Car
word and returns result, but when i search with INNER JOINS a row of Car
word is missing. how to get all rows ?
select word.lemma, synset.pos, synset.definition
from word
left join sense on word.wordid = sense.wordid
left join synset on sense.synsetid = synset.synsetid
where word.lemma = 'car'
order by synset.pos
Result:
SELECT
a.lemma AS `word`,
c.definition,
c.pos AS `part of speech`,
d.sample AS `example sentence`
FROM
word a
INNER JOIN
sense b ON a.wordid = b.wordid
INNER JOIN
synset c ON b.synsetid = c.synsetid
INNER JOIN
sampletable d ON c.synsetid = d.synsetid
WHERE
a.lemma = 'car'
Result:
Change all your INNER JOIN so they say LEFT JOIN instead
The row is disappearing because one of your declared relationships is broken, and there is no matching row in b for this particular row in a, or no matching row in c for a particular row in b etc
By using left joins, the database will keep the row from a instead of removing it, and fill in nulls for every column value from b(or c, whichever table it is) where there is no row that matches a
By looking at the NULLs you will be able to see where the missing row is and you can decide to add it. If you do add it then the INNER JOIN will start showing the row again