title: restaurant table availability check for a particular time using sql
body: <p>I am trying to build a restaurant table management application using yii framework currently i am stuck with retrieving availability of tables for a particular time </p>
  
  <p>i have the following tables</p>
  
  <p>below image shows the table structure i have </p>
  
  <p><img src="https://i.stack.imgur.com/hpnn5.png" alt="enter image description here"></p>
  
  <p>i am getting the avaiable table by using the following piece of code</p>
  
  <pre><code>    $model = new Table;
      $criteria = new CDbCriteria;
      $criteria-&gt;condition = 'floor_id=' . $floorid;
      $rows = $model-&gt;model()-&gt;with(array(
                  'bookingTables' =&gt; array(
                      'condition' =&gt; 'bookingTables.table_id IS NULL'
                      )))-&gt;findAll($criteria);
  </code></pre>
  
  <p>this works only when the table ids are not present in the booking_table table </p>
  
  <p>suppose if say the booking_table table has table ids filled then above code will not work it will always return as not available (no clue how to use time to get available tables)</p>
  
  <p>so how can i get the available tables for a particular time period any solution in yii or sql</p>