I have the following MySQL query:
SELECT u.id, u.ap, q.quests
FROM users u
JOIN(
SELECT count(quest) as 'quests', user
FROM active_quests
WHERE user = 143
) q
ON u.id = q.user
WHERE u.id = 143
The problem I am running into is that sometimes the joined query from the active_quests
table will be NULL
because there will be no entry for that particular user. But this is causing the whole query to become NULL
.
The user will always have an ap
value, but not always a quests
value.
I wanted to do something like SELECT u.id, u.ap, IFNULL(q.quests, 0)
, but it doesn't work.
How do I solve this problem?