How can I query three tables by page? 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.
Reply to discussion (solution)
Select * from table Aunion allselect * from table Bunion allselect * from table Corder by id desc;
SQL code? 123456 select * from table Aunion allselect * from table Bunion allselect * from table Corder by id desc;
Why is this error prompted when I test it?
The used SELECT statements have a different number of columns
Are other fields in the three tables different?
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
What can I do if the table structure is different?
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;
Do not select *. select the field you want.
UNOIN ALL