How can I locate multiple mysql tables and arrange the content according to the last update time?

Source: Internet
Author: User
How can I locate multiple mysql tables in which the content is sorted by the last update time? how can I locate multiple mysql tables in which the content is sorted by the last update time?
The four fields are the same, and only the content is different.
Table name: aaa, bbb, ccc, and ddd

Table fields: title, classid, userid, newstime, classname, images


I want to check the descending order of the last update (newstime) of four independent tables without any association, and how to write the 10 records with userid = 2?
Unix timestamp format of newstime field
The userid field is the user ID field (that is, to find out the last updated content of this user in ten chronological order)


Reply to discussion (solution)

select a.* from aaa as a union all select b.* from bbb as b union all select c.* from ccc as c union all select d.* from ddd as d where userid = 2 orderby newstime desc limit 10

Upstairs.

Test it.

select a.* from aaa as a union all select b.* from bbb as b union all select c.* from ccc as c union all select d.* from ddd as d where userid = 2 orderby newstime desc limit 10



$ Ecms_bq_ SQL = $ empire-> query ("select. * from ds_ecms_nanxie as a union all select B. * from ds_ecms_nvxie as B union all select c. * from ds_ecms_tongxie as c where userid = 1 order by newstime desc limit 10 ");
$ Bqno = 0;
While ($ bqr = $ empire-> fetch ($ ecms_bq_ SQL ))
{


The above write error occurs.
The used SELECT statements have a different number of columns
Select. * from *** _ ecms_nanxie as a union all select B. * from *** _ ecms_nvxie as B union all select c. * from *** _ ecms_tongxie as c where userid = 1 order by newstime desc limit 10

In addition, if there are 5 million rows of data in the four tables, will the query be suspended?

OK. there is a table with fewer fields and more fields.

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.