title: MySQL Union for two tables, then merge in a third table where matched?
body: <p>I have three MySQL tables that I'm trying to query into a single result. As close as I've gotten this, I think it's possible, but I've hit a wall in getting the last part working.</p>
  
  <p>Basically I have two tables (table_one and table_two) which I'm trying to UNION DISTINCT, which works perfectly. It's when I try to bring in the third table that it all blows up and decides to return nothing. I'm sure it's user error  :)</p>
  
  <p>This code may not have everything in the right place for how I'm trying to do it, so maybe I just need a little nudge in the right direction.</p>
  
  <pre><code>SELECT
      part_code,
      name
  FROM
      table_three
  
  WHERE
      table_three.part_code = (
  
      SELECT
          part_code
      FROM
          table_one
  
      UNION DISTINCT
      SELECT
          part_code
      FROM
          table_two
  )
  
  ORDER BY
      name ASC
  </code></pre>
  
  <p>I appreciate any direction someone can offer.</p>