how to use if exists inside db_query
This is really not the ideal way to do this. Instead you may want to try something like:

$query = db_select('node', 'n')
  -&gt;condition('n.type', $type)
  -&gt;condition('n.uid', $uid)
  -&gt;fields('n', array('nid'));

$count = $query-&gt;countQuery()-&gt;execute()-&gt;fetchField();

if ($count) {
  return true;
}

return false;