title: Using IF in MySQL's SELECT subquery
body: <p>I have the following query:</p>
  
  <pre><code>  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` &lt;= $time)
          AND(
             (`ends` &gt; $time)
             OR
             (`ends` IS NULL)
          )
       LIMIT 1
    ) as `account_type`
    FROM `users`
  </code></pre>
  
  <p>I'm wondering how/where do I add an <code>IF</code> statement, so that if the inner SELECT returns NULL (no entries for the user in <code>users-pro</code>, a value <code>1</code> would be returned.</p>
  
  <p>This is what I usually do if there is no subquery:</p>
  
  <pre><code>SELECT IF(`rank` = 1, `rank`, 0) as `rank`
  </code></pre>
  
  <p>However, I don't know how to do this with a subquery.</p>