Aggregate functions in WHERE clause in SQLite

后端 未结 4 1684
青春惊慌失措
青春惊慌失措 2021-02-08 06:29

Simply put, I have a table with, among other things, a column for timestamps. I want to get the row with the most recent (i.e. greatest value) timestamp. Currently I\'m doing th

4条回答
  •  面向向阳花
    2021-02-08 06:46

    you can simply do

    SELECT *, max(timestamp) FROM table

    Edit: As aggregate function can't be used like this so it gives error. I guess what SquareCog had suggested was the best thing to do

    SELECT * FROM table WHERE timestamp = (select max(timestamp) from table)
    

提交回复
热议问题