Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 使用同一表的select查询获取表名_Mysql_Sql_Database - Fatal编程技术网

Mysql 使用同一表的select查询获取表名

Mysql 使用同一表的select查询获取表名,mysql,sql,database,Mysql,Sql,Database,例如,我试图在sql查询中获取表名,我编写该查询是为了从同一个表中获取数据 表1 表二 因此,在执行此查询时 Select * from table_one UNION Select * from table_two 我得到的结果是一个表中两个表的数据,如下所示: 但是我需要在表中再增加一列来查看数据,如下表所示 使用联合所有: select id, name, age, 'table_one' as tabel_name from table_one union all select id,

例如,我试图在sql查询中获取表名,我编写该查询是为了从同一个表中获取数据

表1

表二

因此,在执行此查询时 Select * from table_one UNION Select * from table_two 我得到的结果是一个表中两个表的数据,如下所示:

但是我需要在表中再增加一列来查看数据,如下表所示 使用联合所有:

select id, name, age, 'table_one' as tabel_name
from table_one
union all
select id, name, age, 'table_two'
from table_two