mysql 多个表要怎么查出里面内容按最后更新时间排列
字段四个表都一样,只有内容不一样
表名:aaa,bbb,ccc,ddd   四个表表字段:title,classid,userid,newstime,classname,images
我现在想把没有任何关联的四个独立表,查出最后更新(newstime)的降序,且userid=2,十条记录内容出出来要怎么写?
newstime 字段 Unix时间戳  格式
userid 字段是用户ID的字段(也就是要查出这个用户最后更新的内容按时间降序十条出来)

解决方案 »

  1.   

    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
      

  2.   

    测试一下哦$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 used SELECT statements have 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_tongxie as c where userid=1 order by newstime desc limit 10