mysql 多个结构不同表查询 返回相同字段名

( select ID,数据库原字段名1 AS 统一字段名1,数据库原字段名2 AS 统一字段名2 from 第一个表名 WHERE 1) UNION(联合表查询)
( select ID,数据库原字段名1 AS 统一字段名1,数据库原字段名2 AS 统一字段名2 from 第二个表名 WHERE 1) UNION(联合表查询)
( select ID,数据库原字段名1 AS 统一字段名1,数据库原字段名2 AS 统一字段名2 from 第三个表名 WHERE 1) UNION(联合表查询)
order by ID desc 

例:
原数据表
  test_a

 

  test_b

 

   test_c

 

 

(select ID, a_name AS XM, a_xb AS XB from test_a where 1) UNION
(select ID, b_name AS XM, b_xb As XB from test_b where 1) UNION
(select ID, c_name AS XM, c_xb AS XB from test_c where 1)
order by ID desc
返回结果
(ID是重新生成的 不会原来数据表的ID)
(截图是直接截得没有执行语句可以忽略ID问题)

 

posted @ 2021-07-29 17:14  _理想主义者  阅读(416)  评论(0编辑  收藏  举报