sp123
sp123

Reputation: 47

sql query to add a column to select view

How can I write a select query to view a few columns from a table and add additional columns to it with a default value assigned?

Like Select a,b,c, d="TIM" from table1;, where a,b and c are columns in table1, but "d" isn't.

Upvotes: 0

Views: 1042

Answers (3)

Tony
Tony

Reputation: 764

I assume you want to fetch the rows from table1 where d='TIM' from another table and the ids of these tables are their common fields:

SELECT t1.a,t1.b,t1.c,t2.d 
FROM table1 t1
JOIN table2 t2 ON t1.id = t2.id
WHERE t2.d = 'TIM';

Upvotes: 0

James
James

Reputation: 3015

Like this

select a, b, c, 'TIM' as d
from your_table

Upvotes: 2

Gordon Linoff
Gordon Linoff

Reputation: 1269803

You can just select a constant value:

Select t1.a, t1.b, t1.c, 'TIM' as d
from table1 t1;

Note that SQL in general -- and Oracle in particular -- uses single quotes to delimit strings.

Upvotes: 1

Related Questions