1

I am trying to retrieve data from db with INNER JOIN.

I need the following query executed from drupal's db_select(), query is in normal format :

SELECT uo.* , uop.data FROM `uc_orders` AS uo 
INNER JOIN `uc_order_products` AS uop ON uo.order_id = uop.order_id 
WHERE ( 
  (
     uop.data LIKE '%mfp_donation%'
  ) 
  OR (
     uop.data LIKE '%scholar_donation%'
  ) 
  OR (
     uop.data LIKE '%reunion%'
  )
)

I already tried in drupal, the process is following :

$query = db_select('uc_orders', 'uo')
    ->fields('uo')
    ->fields('uop', array('data'));

$alias = $query->join('uc_order_products', 'uop', "uo.order_id = uop.order_id");

$order = $query->condition(db_or()
       ->condition($alias . '.data', '%mfp_donaiton%', 'LIKE')
       ->condition($alias . '.data', '%scholar_donaiton%', 'LIKE')
       ->condition($alias . '.data', '%reunion%', 'LIKE')
    )
    ->execute()
    ->fetchObject();

All the process is working fine, but the problem is when i execute/fetch the results then i only get the output for ->condition($alias . '.data', '%reunion%', 'LIKE') . I mean i only get the %reunion% part. The first two conditions is not executing i think.

Any suggestion?

1 Answer 1

2

You can use dpq() to inspect your query.
Your query looks good, but I suspect that there's a small error in your condition. You put donaiton, shouldn't it be donation ?

1
  • 1
    Really very very thanks to you for answering. I have also figured out the problem just after i posted this problem. :) Nov 13, 2011 at 3:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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