title: Retrieving data from one table while comparing value from another table
body: <p><strong>Overview</strong></p>
  
  <p>I have two tables as can be seen below:</p>
  
  <pre><code>user_planes
  ----------------------------------
  |id |user_id|plane_id|fuel|status|
  ----------------------------------
  | 2     1        1     1   Ready |
  ----------------------------------
  
  shop_planes
  ------------------------
  |id |name|fuel_capacity|
  ------------------------
  | 1   bob       3      |
  ------------------------
  
  Foreign Key              Primary Key
  user_planes.plane_id &lt;-&gt; shop_planes.id 
  </code></pre>
  
  <p>I want to be able to get every field (<code>SELECT *</code>) in <code>user_planes</code> and <code>name</code> and <code>fuel_capacity</code> based on the following criteria:</p>
  
  <ul>
  <li><code>WHERE user_planes.user_id = ?</code> - Parameter which will be added to the query through PHP.</li>
  <li><code>WHERE user_planes.status = 'Ready'</code></li>
  <li><code>WHERE user_planes.fuel &lt; shop_planes.fuel_capacity</code></li>
  </ul>
  
  <p><strong>The Issue and My Attempts</strong></p>
  
  <p>I've tried <code>JOIN</code> however it retrieves data which doesn't fit that criteria, meaning it gets extra data which is from <code>shop_planes</code> and not <code>user_planes</code>.</p>
  
  <pre><code>SELECT * FROM `user_planes` WHERE fuel IN (SELECT shop_planes.fuel_capacity FROM shop_planes WHERE fuel &lt; shop_planes.fuel_capacity) AND user_planes.user_id = 1 AND status = 'Ready'
  </code></pre>
  
  <p>and</p>
  
  <pre><code>SELECT * FROM `user_planes` INNER JOIN `shop_planes` ON user_planes.fuel &lt; shop_planes.fuel_capacity AND user_planes.user_id = 1 AND user_planes.status = 'Ready'
  </code></pre>
  
  <ul>
  <li>I've searched Stackoverflow and looked through many questions but I've not been able to figure it.</li>
  <li>I've looked up many tutorials but still can't get the desired result.</li>
  </ul>
  
  <p>The desired result is that the query should use the data stored in <code>user_planes</code> to retrieve data from <code>shop_planes</code> while at the same time not getting any excess data from <code>shop_planes</code>.</p>
  
  <p><strong>Disclaimer</strong></p>
  
  <p>I really struggle using <code>JOIN</code> queries, I could use multiple separate queries however I wish to optimise my queries hence I'm trying to bring it in to one query.</p>
  
  <p>If their isn't clarity in the question, please do say, I'll update it to the best of my ability.</p>
  
  <p><strong>Note</strong> - Is there an easy query builder option available either through phpmyadmin or an alternative software?</p>
  
  <p>Thanks in advance.</p>