MySQL multiple tables How to find the contents of the content by the last update time arrangement

Source: Internet
Author: User
MySQL multiple tables How to find the contents of the content by the last update time arrangement
Field four tables are the same, only the content is different
Table name: AAA,BBB,CCC,DDD Four tables

Table field: Title,classid,userid,newstime,classname,images


I now want to put four independent tables without any association, to find out the last update (newstime) of the descending, and userid=2, 10 records of the content out how to write?
Newstime Field UNIX timestamp format
The UserID field is a field of the user ID (that is, to find out what the user last updated by 10 in descending order of time)


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 D DD as D where UserID = 2 newstime desc LIMIT 10

Upstairs positive solution.

Test it, please.

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 D DD as D where UserID = 2 newstime desc LIMIT 10



$ecms _bq_sql= $empire->query ("Select A.* 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
The used SELECT statements has a different number of columns
Select A.* from ***_ecms_nanxie as a UNION ALL select b.* from ***_ecms_nvxie as B union ALL select c.* from ***_ecms_tong Xie as C where userid=1 order by newstime DESC LIMIT 10

In addition to ask, four tables if the data on the 5W, so that the investigation will be suspended animation?

OK, there is a table field less, there is a little more

  • 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.