user12345
user12345

Reputation: 2418

How to add column in a table on fly?

i want to add two tables. But how should i distinguish that which entries is from which table?

table1

col1 
-----
a
b
c

table 2

1
2
3

The result should be:

col1 tablename
----------------
a     table1
b      "
c      "
d     table2
e      "
f      "

Upvotes: 0

Views: 363

Answers (1)

codingbadger
codingbadger

Reputation: 43974

Select Table1.Col1, "Table1" as 'TableName'
From dbo.Table1

Union all

Select Table2.Col1, "Table2" as 'TableName'
From dbo.Table2

Upvotes: 2

Related Questions