三个表分页查询请问如何做到?
例如表A
id name
1 aaa
2 bbb
3 ccc
表B
5 ddd
6 eee
7 fff
表C
4 aaa
8 zzz
9 xxx
如何能查询结果是这样
以ID倒序排序
9 xxx
8 zzz
7 fff
6 eee
5 ddd
4 aaa
3 ccc
2 bbb
1 aaa
最好用SQL完成,因为涉及到分页,所以数组排序的方式不适合
select * from 表Aunion allselect * from 表Bunion allselect * from 表Corder by id desc;
SQL code?123456select * from 表Aunion allselect * from 表Bunion allselect * from 表Corder by id desc;
我测试 ,提示这个错误,是为什么呢
The used SELECT statements have a different number of columns
三个表的 其他字段不同也不可以吗?
例如表A
id a_name
1 aaa
2 bbb
3 ccc
表B
id b_name
5 ddd
6 eee
7 fff
表C
id c_name
4 aaa
8 zzz
9 xxx
表结构不同,有什么办法吗
例如表A
id a_name
1 aaa
2 bbb
3 ccc
表B
id b_name
5 ddd
6 eee
7 fff
表C
id c_name
4 aaa
8 zzz
9 xxx
稍加改动就好:
select * from 表A a union all select * from 表B b union all select * from 表C c order by c.id desc;
你不要select * ,直接选择你要的字段呀。
UNOIN ALL
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号