title: Select distinct values from multiple columns in same table
body: <p>I am trying to construct a single SQL statement that returns unique, non-null values from multiple columns all located in the same table.</p>
  
  <pre><code> SELECT distinct tbl_data.code_1 FROM tbl_data
        WHERE tbl_data.code_1 is not null
   UNION
   SELECT tbl_data.code_2 FROM tbl_data
        WHERE tbl_data.code_2 is not null;
  </code></pre>
  
  <p>For example, tbl_data is as follows:</p>
  
  <pre><code> id   code_1    code_2
   ---  --------  ----------
   1    AB        BC
   2    BC        
   3    DE        EF
   4              BC
  </code></pre>
  
  <p>For the above table, the SQL query should return all unique non-null values from the two columns, namely: AB, BC, DE, EF.</p>
  
  <p>I'm fairly new to SQL. My statement above works, but is there a cleaner way to write this SQL statement, since the columns are from the same table?</p>