title: MySQL: Select in three tables
body: <p>I am working on a system where some couriers may request their preferred tours. If there is more than one employee who requests a particular tour, I want to give it to the one who started working for us first. I want to show a smilie or something else on the overview page like this </p>
  
  <ol>
  <li>Tour available  </li>
  <li>You would kick somebody out</li>
  <li>Already requested by somebody who started first</li>
  </ol>
  
  <p>I tried it for several hours, but I can not get the MySQL code for it.
  I have 3 relevant tables.</p>
  
  <ol>
  <li>Employees:
  <ul>
  <li>employeeid</li>
  <li>date of entry</li>
  <li>...</li>
  </ul></li>
  <li>Tours
  <ul>
  <li>tourid</li>
  <li>details...</li>
  </ul></li>
  <li>Requests
  <ul>
  <li>employee-id</li>
  <li>tourid</li>
  </ul></li>
  </ol>
  
  <p>I would want to select all tours including their details -> easy</p>
  
  <p>I want to (at least) add another field counting the requests on that tour for further queries. I guess I need a select with the <code>tourid</code> from the 1. query</p>
  
  <p>The best would be a query including an if-else statement with the result, that the field behind the <code>tourid</code> would be NULL if the tour is available or showing the date of entry of the oldest employee who requested the tour if the requestcount > 0</p>
  
  <p>I am very thankful for any advice on that!</p>
  
  <p>Thank you!</p>