How can I query three tables by page? How can I query three tables by page? For example, table Aid & nbsp; name1 & nbsp; aaa2 & nbsp; bbb3 & nbsp; in ccc table B5 & nbsp; ddd6 & n, how does one perform paging queries?
How can I query three tables by page?
For example, Table
Id name
1 aaa
2 bbb
3 ccc
Table B
5 ddd
6 eee
7 fff
Table C
4 aaa
8 zzz
9 xxx
How can I query the results?
Sort by ID in reverse order
9 xxx
8 zzz
7 fff
6 eee
5 ddd
4 aaa
3 ccc
2 bbb
1 aaa
It is best to use SQL. because paging is involved, the array sorting method is not suitable for SQL.
------ Solution --------------------
Select * from Table
Union all
Select * from Table B
Union all
Select * from Table C
Order by id desc;
------ Solution --------------------
Reference:
For example, Table
Id a_name
1 aaa
2 bbb
3 ccc
Table B
Id B _name
5 ddd
6 eee
7 fff
Table C
Id c_name
4 aaa
8 zzz
9 xxx
Slightly changed:
Select * from table A a union all select * from Table B union all select * from Table C c order by c. id desc;