Possible Duplicate:
Is it possible to join dynamic tables (subqueries) using db_select()?
I have this part of a query running in drupal with db_query.
LEFT JOIN (SELECT ogmk.gid, ogmk.etid, kompas.* FROM og_membership ogmk
INNER JOIN node kompas ON kompas.nid=ogmk.etid AND kompas.type='kompas'
INNER JOIN publication_date pd ON pd.nid=kompas.nid
WHERE pd.published_at > :start AND pd.published_at < :end AND kompas.status = 1
) ogm_kompas
ON ogm_kompas.gid=og.gid
The left join should give records if they are available. If not the fields will be null.
How can I transform this to the db_select method with a selectQuery, so I can use the theme function for sorting and paging?
Thanks in advance for your answer.