title: SELECT value from table because two conditions are not met
body: <p>I have three tables on my database:</p>
  
  <p><strong>ts_room</strong></p>
  
  <p>Fields:</p>
  
  <pre><code>id (PK)
  capacity    
  img 
  notes   
  building_id 
  roomstructure_id    
  lecturestyle_id
  </code></pre>
  
  <p><strong>ts_request</strong></p>
  
  <p>Fields</p>
  
  <pre><code>id (PK)
  day_id
  period_id
  roompref_id (FK &gt; ts_roompref.id)
  </code></pre>
  
  <p><strong>ts_roompref</strong></p>
  
  <pre><code>id (PK)      
  request_id (FK &gt; ts_request.id)      
  room_id (FK &gt; ts_room.id)
  </code></pre>
  
  <p>I would like to write a MySQL PDO query that selects rows from <strong>ts_room</strong> provided that after running the rows on <strong>ts_roompref</strong> (checking ts_roompref.room_id against ts_room.id) and finding a match - we would then look up the value in <strong>ts_request</strong> and see whether <strong>day_id</strong> and <strong>period_id</strong> both match 1. It would return the total count.</p>
  
  <p>I hope the above explanation makes sense. </p>
  
  <p>Essentially - requests for rooms are made with this system and <strong>ts_roompref</strong> stores the room preferences made for each request. I am trying to find out whether a particular room is booked on a <strong>day</strong> and <strong>period</strong> (denoted by <strong>day_id</strong> and <strong>period_id</strong> in the <strong>ts_request</strong> table), in this case Monday (1) and period (1).</p>