(
SELECT
`a`.`id` AS `id`,
`a`.`name` AS `name`,
'table1' AS `TABLE_NAME`
FROM
`table1` `a`
ORDER BY
`a`.`role`
LIMIT 5
)
UNION
(
SELECT
`b`.`id` AS `id`,
`b`.`student_name` AS `student_name`,
'tavle2' AS `TABLE_NAME`
FROM
`table2` `b`
ORDER BY
`b`.`student_role`
LIMIT 5
)
2条答案
按热度按时间nwsw7zdq1#
你可以用
union all
```select *, 'table1' as table_name from table1
union all
select *, 'table2' as table_name from table2
create table new_table
select *, 'table1' as table_name from table1
union all
select *, 'table2' as table_name from table2
b1payxdu2#