Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I had a query (part of a big query):

$query->add_where(1, '10',
  db_select('users_roles', 'r')
    ->fields('r', array('rid'))
    ->where('r.uid = users_node__users_roles.uid'),
  'NOT IN');

In that query there is a subquery that returns all the the rid (role id) of a specific user uid.
It will work fine if there is at least one role for a user in the role table, otherwise the subquery will return empty which will make the query:

10 NOT IN ()

How can i change the value of rid to 0 if it is empty (if the user has no roles)?

Is there any mysql case conditions to check empty of a field?

Thanks in advance. Prem

share|improve this question
    
Yes MySQL has conditionals: dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html –  Clive Mar 17 at 11:04
    
@Clive please set the subquery query for me –  Prem Shankar Mar 17 at 11:12
    
Sorry, what do you mean? If you mean "you write it for me", then no, sorry, you'll need to do that yourself :) Pure MySQL questions are off-topic here - get your query working exactly as it should with a plain SQL string; if you have trouble converting that working query to Drupal's API, that's when to ask here –  Clive Mar 17 at 11:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.