当前位置:Gxlcms > PHP教程 > mysql多个表要怎么查出里面内容按最后更新时间排列

mysql多个表要怎么查出里面内容按最后更新时间排列

时间:2021-07-01 10:21:17 帮助过:14人阅读

mysql 多个表要怎么查出里面内容按最后更新时间排列
字段四个表都一样,只有内容不一样
表名:aaa,bbb,ccc,ddd 四个表

表字段:title,classid,userid,newstime,classname,images


我现在想把没有任何关联的四个独立表,查出最后更新(newstime)的降序,且userid=2,十条记录内容出出来要怎么写?
newstime 字段 Unix时间戳 格式
userid 字段是用户ID的字段(也就是要查出这个用户最后更新的内容按时间降序十条出来)


回复讨论(解决方案)

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

楼上正解。

测试一下哦

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

另外问下,四个表如果数据上5W条的话,这样查会不会假死了?

OK了,是有个表字段更少些,有个多些

人气教程排行