Three-table paging query How do I do that?
For example, table A
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 so
Sort by Reverse ID
9 xxx
8 zzz
7 FFF
6 eee
5 DDD
4 AAA
3 CCC
2 BBB
1 AAA
It's best to do it with SQL, because paging is involved, so the way the array is sorted doesn't fit
Reply to discussion (solution)
SELECT * FROM Table aunion Allselect * FROM table bunion Allselect * FROM table corder by id desc;
SQL code?123456select * FROM table aunion Allselect * FROM table bunion Allselect * FROM table corder by id desc;
I'm testing, suggesting this error, for what?
The used SELECT statements has a different number of columns
Is it not possible to have the other fields of the three tables different?
For example, table A
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
Table structure is different, is there any way?
For example, table A
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
A little change is good:
SELECT * FROM Table a UNION ALL SELECT * FROM table b b UNION ALL SELECT * FROM table C c ORDER by c.id Desc;
You don't need a SELECT *, just choose the field you want.
Unoin All