Reputation: 47
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
Reputation: 764
I assume you want to fetch the rows from table1
where d='TIM'
from another table and the id
s 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
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