Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Confused between constant and alias sql query

I have to create a constant column with the alias ‘Region’ in each query. Also, the first query must be labeled the ‘Midwest Region’ and the second ‘Pacific Northwest Region’. I am confused on how I am supposed to alias each one while also setting a constant? I tried inputting "as" in multiple areas but I have just been getting syntax errors. I am new to SQL.

select *
from dealerships
where state in ('IL','IN', 'WI', 'MI')

select *
from dealerships d
where state in ('WA', 'OR', 'ID')

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You wrote

SELECT *
...
SELECT *

For "constant" column values you want

SELECT *, 'Midwest Region' AS region
...
SELECT *, 'Pacific Northwest Region' AS region

As far as the UNION thing goes,
there’s more than one place on the internet
where you could RTFM, including: https://en.wikipedia.org/wiki/Set_operations_(SQL)#UNION_operator

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading