I have the following query:
SELECT `users`.`id`, `login`, `fullname`, `active`, `sex`, `height`,
`special-title`, `language`, `body-fat`,
`main-photo-id`, `main-photo-offset`, `weight`,
`objective`, `level`, `config-comments-type`,
(
SELECT `type`
FROM `users-pro`
WHERE
(`user` = `users`.`id`)
AND
(`starts` <= $time)
AND(
(`ends` > $time)
OR
(`ends` IS NULL)
)
LIMIT 1
) as `account_type`
FROM `users`
I'm wondering how/where do I add an IF statement, so that if the inner SELECT returns NULL (no entries for the user in users-pro, a value 1 would be returned.
This is what I usually do if there is no subquery:
SELECT IF(`rank` = 1, `rank`, 0) as `rank`
However, I don't know how to do this with a subquery.