• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 3年前 (2022-01-23) 11次浏览 已收录 0个评论
文章目录[隐藏]

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

5本文来源gao!daima.com搞$代!码#网#

搞代gaodaima码

表都一样,只有内容不一样
表名: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了,是有个表字段更少些,有个多些


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:mysql 多个表要怎么查出里面内容按最后更新时间排列

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址