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.