Select only if row not exists in joined table I have a db_select that selects row from t_project_proposal_writer table only if in joined t_project_milestone table row with milestone_id 10 is found:

$query = db_select('t_project_proposal_writer', 'p')-&gt;fields('p');
$query-&gt;innerJoin('t_project_milestone', 'm', 'p.id=m.proposal_id');
$query-&gt;condition('p.initiative_nid', $node-&gt;nid)-&gt;condition('m.milestone_id', 10);


One project row can have 10 milestone rows. Now I need to do another query that selects only the rows from t_project_proposal_writer where milestone_id 10 not exists in joined t_project_milestone.

Is there any other possiblity to do that, instead of query all the projects and iterate throught them while checking if milestone 10 exists?
You can use isNull() method : 

$query = db_select('scald_atoms', 'a');
$query-&gt;fields('a', array('sid','title'));
$query-&gt;leftjoin('table_name','table_alias','table_alias.entity_id = a.sid');
$query-&gt;isNull('table_alias.mon_field_value');
$query-&gt;execute();
$query-&gt;fetchAllAssoc('nid');


with your example something like that should do it : 

$query = db_select('t_project_proposal_writer', 'p')-&gt;fields('p');
$query-&gt;leftjoin('t_project_milestone', 'm', 'p.id=m.proposal_id');
$query-&gt;isNull('m.milestone_id');