title: How to inner join two select queries on same table
body: <p>I am stuck...  A 'data' table with columns 'value' and 'datatype' is populated with engine load and vehicle speed and each record is stamped with date, time, lat, long.  I want to query for engine load over 10% while the vehicle is moving (e.g. speed > 0).  I can create a query to select the engine load and I can create a query to select the vehicle speed but how do I create a query to select engine load when > 10% AND the Vehicle is moving where their date, time lat, and long are equal?</p>
  
  <p>This Query does not work, but it provides a jist of what I am trying to do.  Can anyone help me create a query?</p>
  
  <pre>
  tables
  TName:  data
  PK  datakey
      value
  fk1 dataeventkey
  fk2 datatypenamekey
  
  TName: datatypename
  PK datatypenamekey
     datatypename
  
  TName: dataevent
  PK dataeventkey
     datetime
     lat
     long
  </pre>
  
  <pre><code>SELECT 
     d1.datetime 
  FROM 
      (data INNER JOIN datatypename ON data.datatypenamekey = datatypename.datatypenamekey    
      INNER JOIN dataevent ON dataevent.dataeventkey = data.dataeventkey) d1  
  WHERE 
      ( d1.datatypename = "Engine Load [%]" AND d1.value &gt; 10 )
  
   INNER JOIN
  
  SELECT 
      d2.datetime  
  FROM 
      (data INNER JOIN datatypename ON data.datatypenamekey = datatypename.datatypenamekey  
      INNER JOIN dataevent ON dataevent.dataeventkey = data.dataeventkey) d2  
  WHERE 
      ( d2.datatypename = "Vehicle Speed [mph]" AND d2.value &gt; 0 ) 
  
      ON d1.datetime = d2.datetime
  </code></pre>