1

I have a query that contains a UNION operator. If I ran my query it runs perfectly straight on the database but I am getting an empty result in Drupal.

Here is a simplified version of the query:

$result = db_query("
    SELECT *
    FROM (
    SELECT
    agent_number
    FROM table1
    WHERE agent_number IN (':agent_numbers')
    UNION
    SELECT
    agent_number
    FROM table2
    WHERE agent_number IN (':agent_numbers')) t", array(
      ':agent_numbers' => $agent_ids,
    )
  )->fetchAll();

Is it that db_query() doesn't support UNION?

1 Answer 1

0

Yes, db_query() does support UNION. I had a problem with my query:

WHERE agent_number IN (':agent_numbers')

Should be:

WHERE agent_number IN (:agent_numbers)

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.