title: MySQL Select Based on Conditional Select
body: <p>I have my structure set up so that any entry could contain a reference to another entry to fill in the missing details.</p>
  
  <pre><code>ID,  NAME, DESCRIPTION, REFERENCE
  0,  Stuff,      Things, -1
  1,       ,            , 0
  2, Things,       Stuff, -1
  </code></pre>
  
  <p>I want to be able to return all the results for the table and if an entry requires a reference to another entry to complete the data, to fill the reference field with the data. I also want to keep the original ID of the reference field. I also want the fields that don't require a reference to be left alone.</p>
  
  <pre><code>SELECT `ID`, `REFERENCE` FROM `details` as `t`
       IF `REFERENCE` != -1 THEN
            SELECT *, `t`.`REFERENCE` as `ORIGINAL_ID` FROM `details` WHERE `ID` = `t`.`REFERENCE`
       ELSE
            SELECT * FROM `details` WHERE `ID` = `t`.`ID`
  </code></pre>
  
  <p>Obviously that won't work, but I'm just trying to demonstrate to you what I think I want. Is this possible? Thanks for reading.</p>