1

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?

ALR
  • 441
  • 2
  • 7
  • 19

1 Answers1

3

Use LEFT JOJN instead of join . Only join will imply inner join . Reference

Community
  • 1
  • 1
Web Artisan
  • 1,870
  • 3
  • 23
  • 33