How to query three tables by page

Source: Internet
Author: User
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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.