I read several questions about this issue on stackoverflow : It seems that COUNT should be used with the right Joining to display sums of every items, including the ones summing zero.
I'm not really able to make it with my case, after several hours of headache...
Well, I have 2 tables. The first one is called "words2", with a list of words. The second one is called "links2". It's linking together two words : idWord1 and idWord2. (There are no links linking together two identical words)
For each word, I would like to know how many links are used, even if there is no link.
This is my query :
SELECT *, COUNT(*) AS qty
FROM (
SELECT *
FROM words2
LEFT OUTER JOIN links2 AS linksA ON words2.idWord = linksA.idWord1
UNION
SELECT *
FROM words2
LEFT OUTER JOIN links2 AS linksB ON words2.idWord = linksB.idWord2
) AS tmp
WHERE idUser = 3 AND linkType = 'individual'
GROUP BY word ORDER BY word
It works fine unless I don't have any results for the unused words, which are not displayed.
Thank you very much for your help!