Select nodes based on entity reference value
You need to JOIN on nid and vid (entity fields are stored per nid/vid), add a JOIN to your email field table, set the fields to select the email value, and set your WHERE clause to entity reference target.

$query = db_select('node', 'n');
$query-&gt;join("field_data_field_offline_course_reference", "t", "t.entity_id = n.nid AND t.revision_id = n.vid");
$query-&gt;join("field_data_field_offline_course_student_ema", "e", "e.entity_id = n.nid AND e.revision_id = n.vid");
$query-&gt;fields("e", array("field_offline_course_student_ema_value"))
    -&gt;condition('n.type', 'students')
    -&gt;condition('t.field_offline_course_reference_target_id', $courseinfo);