How can I use a variable such as ‘AS uniqueName’ in the select in the same select later on?
I am trying to put some simple logic inside the select so I dont have to iterate through the result set just to do something easy:
SELECT
CASE emp_crns.ansi_class
when -1 then 'N'
when 150 then 0
when 300 then 1
when 600 then 2
when 900 then 3
when 1500 then 4
when 2500 then 6
when 3500 then 8
else 'X'
end AS crnAnsiClassCode,
CONCAT('REV. ', crnAnsiClassCode, ' ', emp_models.name) AS modelName
FROM
emp_models
JOIN
emp_revisions ON emp_revisions.id=emp_models.revision_id
JOIN
emp_crns ON emp_crns.id=emp_revisions.crn_id
You can use a sub-query to access the alias that you provided: