1

How can I write a subquery in Drupal 7? My query is the following:

SELECT N.nid AS n_nid
FROM   workflow_node WN
LEFT OUTER JOIN node N
ON WN.nid = N.tnid
WHERE ( WN.sid IN (SELECT WT.sid
  FROM (SELECT sid,
    Concat(',', roles, ',') AS role_stamp
    FROM workflow_transitions) AS WT
  WHERE  role_stamp LIKE '%5%')
AND N.language = "en" )  

1 Answer 1

5

You can assign your sub query to a new variable say subquery and pass it to the db_select using

$query->condition('WN.sid', $subquery, 'IN');

You can know more about this by visiting this page.

Your Answer

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