【问题标题】:select data with latest Timestamp from several tables with mySQL [closed]使用 mySQL 从多个表中选择具有最新时间戳的数据 [关闭]
【发布时间】:2015-11-09 14:49:07
【问题描述】:

我的数据库中有 7 个表。 我想从表中获取 20 个 latest 插入数据。 这些表都是这样构建的:

   id          Link         date           
========-----========----==============
integer       String      Timestamp

【问题讨论】:

  • UNION ALL, order by, LIMIT 20. (但为什么有 7 个相似的表格?)
  • ORDER BY date DESC

标签: mysql sql timestamp


【解决方案1】:
select * from
(
Select date from table
union all
select date from table2
) as t
order by t.date desc
limit 20

【讨论】:

  • 不是order by t.date desc 吗?
  • 是的!您使用 desc 从最大的开始。
  • @JackJreigeChalouhy 谢谢,这很好:)
  • 我添加了一些参数,所以它应该工作得更快:select * from ( ( select date from table order by date desc limit 20 ) union all ( select date from table2 order by date desc limit 20 ) ... ) as t order by t.date desc limit 20
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-08
  • 1970-01-01
  • 2014-01-16
相关资源
最近更新 更多