I am working with MySQL making a list of top 100 keywords associated with scientific articles. The subquery basically provides the top 100 keywords along with the number of times that appear globally .
Now, what I want is to filter by country of those 100 keywords but with one condition: if that country has not worked with these keywords, I want the query to return a 0 in said row and that no omit it . That is, the query must also return 100 rows.
Current query
SELECT tAIK.INDEX_KEYWORDS,
COUNT(*)
FROM tARTICLE tA, tARTICLE_tCOUNTRIES tAC, tARTICLE_tINDEX_KEYWORDS tAIK
INNER JOIN
(SELECT INDEX_KEYWORDS,
COUNT(*)
FROM tARTICLE tA, tARTICLE_tINDEX_KEYWORDS tAIK
WHERE tAIK.DOI = tA.DOI
GROUP BY INDEX_KEYWORDS
ORDER BY COUNT(*) DESC, INDEX_KEYWORDS
LIMIT 100) AUX -- Subquery
ON tAIK.INDEX_KEYWORDS = AUX.INDEX_KEYWORDS
WHERE tA.DOI = tAIK.DOI
AND tA.DOI = tAC.DOI
AND tAC.COUNTRY = "Canada"
GROUP BY tAIK.INDEX_KEYWORDS
ORDER BY COUNT(*) DESC, tAIK.INDEX_KEYWORDS;
References
I have researched on my account seeing functions such as ISNULL , CASE or COALESCE but they do not work for me. I have also tried to use a RIGHT JOIN instead of the INNER JOIN based on the graphic representation of the JOINS in SQL .
Thanks in advance!