Home > Backend Development > PHP Tutorial > mysql 多个表要怎么查出里面内容按最后更新时间排列

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

WBOY
Release: 2016-06-23 14:25:53
Original
994 people have browsed it

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
Copy after login
Copy after login

楼上正解。

测试一下哦

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
Copy after login
Copy after login



$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了,是有个表字段更少些,有个多些

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template