title: MySQL JOIN to replace IDs with value from another table
body: <p>Say I have an <em>Encoding</em> table that containing various types, for ex:</p>
  
  <pre><code>    ID  EncodingName
      ------------------
      1   UTF-8
      2   ISO-8859-1
  </code></pre>
  
  <p>And another <em>EncodingMapping</em> that uses these IDs to keep track of which encodings to convert From and To:</p>
  
  <pre><code>    ID  ItemId_FK  EncodingFromId_FK  EncodingToId_FK
      -------------------------------------------------
      1   45         2                  1  
      2   78         1                  2
  </code></pre>
  
  <p>I want to create an SQL statement that creates the following result when ItemId_FK = 45 (for example):</p>
  
  <pre><code>   FromEncoding  ToEncoding
     -------------------------
     ISO-8859-1    UTF-8
  </code></pre>
  
  <p>Seems like it would be simple enough, but I cannot a get a JOIN to work by returning a single row in this format.</p>
  
  <p>What I have so far (THIS IS WRONG):</p>
  
  <pre><code>   SELECT EncodingName As FromEncoding, EncodingName As ToEncoding
     FROM Encoding
     LEFT JOIN EncodingMapping As em
     ON Encoding.ID = em.EncodingFromId_FK OR Encoding.ID = em.EncodingToId_FK
     WHERE ItemId_FK = 45
  </code></pre>