Display table name in select statement

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

exact question:

we have common columns in two tables. we show entries with

select column_name from table_name_1 
union
select column_name from table_name_2

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

we need a conclusion as follows

eg:

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

Is it possible

+5
source share
1 answer
select 'table1', * from table1 
union
select 'table2',* from table2
+14
source

All Articles