Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a new column in a select query

In MS Access, I want to insert a new column into the returned result of a select query. The new column has the same value for every row. For example, my select returns columns A, B and I want C to be the new column created by the select query:

A   B   C ---------- a1  b1  c a2  b2  c a3  b3  c 
like image 452
Martin08 Avatar asked Sep 22 '10 13:09

Martin08


People also ask

How do I add a new column to a SELECT query?

The basic syntax for adding a new column is as follows: ALTER TABLE table_name ADD column_name data_type constraints; The SQL ALTER TABLE add column statement we have written above takes four arguments. First, we specify the name of our table.

How do I add a column to a SELECT statement in SQL Server?

Manually add it when you build the query: SELECT 'Site1' AS SiteName, t1. column, t1. column2 FROM t1 UNION ALL SELECT 'Site2' AS SiteName, t2.


1 Answers

select A, B, 'c' as C from MyTable 
like image 127
D'Arcy Rittich Avatar answered Oct 05 '22 17:10

D'Arcy Rittich