title: SQL Use Result from one Query for another Query
body: <p>This is an excerpt from one table:</p>
  
  <pre><code>| id | type    | other_id | def_id | ref_def_id|
  | 1  | int     | NULL     |  5     | NULL     |
  | 2  | string  | NULL     |  5     | NULL     |
  | 3  | int     | NULL     |  5     | NULL     |
  | 20 | ref     | 3        |  NULL  | 5        |
  | 21 | ref     | 4        |  NULL  | 5        | 
  | 22 | ref     | 5        |  NULL  | 5        |  
  </code></pre>
  
  <p>What I want is to find entries with type ref. Then I would for example have this one entry in my result: </p>
  
  <pre><code>| 22 | ref     | 5        |  NULL  | 5        |  
  </code></pre>
  
  <p>The problem I am facing is that I now want to combine this entry with other entries of the same table where def_id = 5. </p>
  
  <p>So I would get all entries with def_id = 5 for this specific ref type as result. I somehow need the output from my first query, check what the ref_def_id is and then make another query for this id.</p>
  
  <p>I really have problems to understand how to proceed. Any input is much appreciated.</p>