获取包含列的两个最高值的所有行

时间:2015-12-10 16:45:31

标签: sql sqlite

示例表如下所示:

 last_update | notes
-------------+--------------------
 1449619200  | not that important
 1449619200  | rather useless
 1449705600  | interesting
 1449792000  | very important
 1449792000  | very useful

现在我想要一个SQLite命令输出所有具有两个最新更新时间戳的行(即1449705600和1449792000),以便输出表如下所示:

 last_update | notes
-------------+--------------------
 1449705600  | interesting
 1449792000  | very important
 1449792000  | very useful

命令应该是什么样的?

1 个答案:

答案 0 :(得分:1)

select * from yourtable 
where last_update in (select distinct last_update 
                      from yourtable
                      order by last_update desc
                      limit 2)