title: Selecting distinct values from joined results in Mysql
body: <p>I am trying to access complete data from two tables in mysql and then find distinct values of a column from the resulting set. tried doing with nested query as follows :-</p>
  
  <pre><code>Select distinct s.BlockName 
  from (SELECT * 
        FROM constucted
        LEFT JOIN required ON constucted.BlockName = required.BlockName 
  
        UNION
  
        SELECT * 
        FROM constucted
        RIGHT JOIN required ON constucted.BlockName = required.BlockName
       ) s
  </code></pre>
  
  <p>As mentioned in <a href="https://stackoverflow.com/questions/19323577/selecting-distinct-values-from-joined-results">Stackoverflow Reference</a>
  and also tried using the with keyword as follows :-</p>
  
  <pre><code>WITH CTE
  AS
  (
     SELECT * 
     FROM constucted
     LEFT JOIN required ON constucted.BlockName = required.BlockName
  
     UNION
  
     SELECT * 
     FROM constucted
     RIGHT JOIN required ON constucted.BlockName = required.BlockName
  )
  SELECT DISTINCT BlockName
  FROM CTE
  </code></pre>
  
  <p>But unable to find the distinct value for the column BlockName unable to prepare a query for the same.</p>