我有表1
table1
id int
myvalue text
datevalue datetime ('2016-02-23 19:25:02')
和表2
table2
id int
myvalue text
datevalue datetime ('2016-02-23 19:27:58')
我想为 table1 和 table2 选择最近的 5 行
我猜这是一个 ORDER BY datevalue DESC LIMIT 5 ...
但是我尝试了很多方法都没有成功!
谢谢:)
最佳答案
对于两个表一起:
SELECT * FROM (
SELECT * FROM Table1
UNION ALL
SELECT * FROM Table2)
ORDER BY datevalue desc LIMIT 5
对于每个表分别:
SELECT * FROM Table1
ORDER BY datevalue desc LIMIT 5
UNION ALL
SELECT * FROM Table2
ORDER BY datevalue desc LIMIT 5
关于mysql - 如何从表中选择最新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35628952/