$query = db_select('drupal5users', 'udf');
$query->leftJoin('drupal5users_roles', 'ur');
$query->fields('udf', array('uid','name','pass','mail','created','access','login','status','language','init'));
$query->fields('ur', array('rid'));

The above gives me the following error:

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') subquery' at line 1.

If I comment out $query->leftJoin and the second $query->fields line, it works, so the problem lies with leftJoin. What am I doing wrong here?

$query->leftJoin('drupal5users_roles', 'ur', 'udf.uid = ur.uid');
  • Thanks, worked like a charm! Now just to fix up whatever logic error I still have left in my code :). – Peter Nov 7 '11 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.