tags:

views:

70

answers:

1

Hi,

I need to display the table name in the select statement. how?

exact question:

we have common columns in two tables. we are displaying the records by using

select column_name from table_name_1 
union
select column_name from table_name_2

But the requirement is, we need to display the source table_name along with the data. consider a,c are present in table_1 and b,d are present in table_2.

we need the output in the following way

eg:

column_name                     table_name
a                                          table_1
b                                          table_2
c                                          table_1
d                                          table_2
.......................................................
......................................................

Is this possible

+11  A: 
select 'table1', * from table1 
union
select 'table2',* from table2
Hassan Syed
Thanks.. it worked for me..!!!
msbyuva