title: Count distinct Alias in SQL?
body: <p>I am practicing my SQL coding and wanted to expand more on a practice example. I am trying to get a distinct count after using CONCAT to generate an alias. I keep running into errors and can't seem to find a correct way of doing this. Below is my code</p>
  <pre><code>SELECT 
  concat(product_code, product_color) as new_product_code
  count (distinct new_product_code)
   FROM `hands-on-project-automobile.customer_data.customer_purchase` 
   where 
   product = 'couch'
   order by new_product_code desc
  </code></pre>
  <p>##update##
  I am getting a little closer to what I am wanting to achieve thanks to all the feedback. In my new code I attempted my first subquery. It worked, but I still am missing second column giving me a count of the number of new_product_code. e.g. grey couches 2, white couches 3,</p>
  <pre><code>SELECT 
     distinct new_product_code
     
  FROM 
      (SELECT 
           concat(product_code, product_color) as new_product_code
          FROM `hands-on-project-automobile.customer_data.customer_purchase` 
          where 
          product = 'couch'
          order by new_product_code desc
      )
  </code></pre>
  <p>screenshot of what I am attempting<a href="https://i.stack.imgur.com/sXPmE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sXPmE.png" alt="enter image description here" /></a></p>
  <p>##update 2##
  Shout out to @shawnt00 for help and everyone else. the final code:</p>
  <pre><code>SELECT 
     distinct new_product_code,
     count(*) 
     
  FROM 
      (SELECT 
           concat(product_code, product_color) as new_product_code
          FROM `hands-on-project-automobile.customer_data.customer_purchase` 
          where 
          product = 'couch'
          order by new_product_code desc
      )
      group by new_product_code 
  </code></pre>
  <p>and the output
  <a href="https://i.stack.imgur.com/JCUVJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JCUVJ.png" alt="enter image description here" /></a></p>