Get blank value if field value is not available I have following query on my D7 project 

$query = db_select('payment_logs', 'p');
$query-&gt;join('field_data_field_frequency', 'd', 'd.entity_id = p.nid');
$query-&gt;join('field_data_field_maid_id', 'm', 'm.entity_id = p.nid');
$query-&gt;join('field_data_field_coupon_code', 'c', 'c.entity_id = p.nid');
$query-&gt;join('field_data_field_tip_amount', 't', 't.entity_id = p.nid');
$query-&gt;fields('p');
$query-&gt;fields('d', array('field_frequency_tid'));
$query-&gt;fields('m', array('field_maid_id_uid'));
$query-&gt;fields('c', array('field_coupon_code_value'));
$query-&gt;fields('t', array('field_tip_amount_value'));
$query-&gt;condition('p.section','booking','=');
$result = $query-&gt;execute();
$res = $result-&gt;fetchAll();
return $res;


this query returns data where field_tip_amount_value and field_coupon_code_value are available. I want to get all data with blank field values if not available. these two fields are optional other fields will be there always. so if tip or coupon is not there data must return blank for this field.

I was doing it with separate queries before but it was taking too much time with multiple loops. is there a way to get it done with join ?
You can change $query-&gt;join to $query-&gt;leftjoin.

This will cause the query to return a row, even if there's no entry in the joined table.

Hope this helps.