title: Multiple queries, or nested?
body: <p>I have two channels.</p>
  
  <p>The first channel is 'booking'. This holds the <code>member_id</code> and a <code>tour_id</code>. </p>
  
  <p>The second channel is 'tours'. This holds the tour details, referenced by the above <code>tour_id</code>.</p>
  
  <p>I need to query fields within the 'tours' channel, getting the <code>tour_id</code> for those where the query was met. I then need to find all 'booking' entries where the <code>tour_id</code> matches one of those were the query was true.</p>
  
  <p>Is it better to complete two SQL queries, or a nested query? If nested, how?</p>
  
  <hr>
  
  <p><strong>exp_channel_data</strong>
  |channel_id|entry_id|field_id_1|...|</p>
  
  <p><strong>exp_channel_titles</strong>
  |channel_id|entry_id|author_id|...|</p>
  
  <pre><code>SELECT titles.author_id
  FROM exp_channel_data AS tours
  LEFT JOIN exp_channel_titles AS titles ON bookings.entry_id = titles.entry_id
  LEFT JOIN exp_channel_data AS bookings
      ON tours.entry_id = bookings.entry_id
      AND bookings.channel_id = '17'
  WHERE tours.channel_id = '5'
  AND tours.field_id_34 = 'DSV04'
  </code></pre>
  
  <hr>
  
  <pre><code>$sql_1 = "
      SELECT entry_id
      FROM exp_channel_data 
      WHERE field_id_34 LIKE 'adas%'
  ";
  
  $query_1 = ee()-&gt;db-&gt;query($sql_1);
  $test = $query_1-&gt;result_array();
  
  $uids = Array();
  foreach($test as $u) $uids[] = $u['entry_id'];
  $list = implode(",",$uids);
  
  
  $sql_2 = "
      SELECT ct.author_id
      FROM exp_channel_data AS cd
      LEFT JOIN exp_channel_titles AS ct ON cd.entry_id = ct.entry_id 
      WHERE field_id_227 IN ($list)
  ";
  
  $query_2 = ee()-&gt;db-&gt;query($sql_2);
  $test_2 = $query_2-&gt;result_array();
  </code></pre>