Adding A Column that doesn't exist in a query
18,361
Solution 1
Yes, sure:
select a, b, 3 as c from table_test
That's it. It works on three db engines you've mentioned.
Solution 2
You should use:
SELECT A,B, 3 AS C FROM TABLE_TEST
Solution 3
you can use as
Select a,b, 3 as c from table
This is known as alias
Related videos on Youtube
Author by
Devin Dixon
Updated on April 10, 2020Comments
-
Devin Dixon about 4 years
I want to add a column in a query that does not exist in a table and return it as a result. So lets say TABLE_TEST has column A, B and I want to return values for A, B and C. I am trying to do
SELECT A, B, C=3 FROM TABLE_TEST
or
SELECT *, C=3 FROM TABLE_TEST
Can this be done in MySQL, Postgresel or MSSQL?
-
NKCSS about 13 yearsYou could also do 3 as "My Fake Column" if you want to incorporate spaces in the column name.
-
NKCSS about 13 yearsYou are missing a comma after B, which makes the query invalid.