How to write inner subquery in db_select() method?
You can assign your sub query to a new variable say subquery and pass it to the db_select using

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


You can know more about this by visiting this page.