SELECt * FROM my_table -- standard stuff WHERe user_2 = 22 -- predicate ORDER BY timestamp DESC -- this means highest number (most recent) first LIMIT 1; -- just want the first row
编辑:
顺便说一句,如果您想知道为什么原来的查询不起作用,让我们分解一下:
- 从
my_table
…中选择一些东西 - 其中
user_2
= 22 - 和
timestamp
= (有些值,暂时搁置) - 限制1
现在,回到该
timestamp值,它来自您的子查询:
SELECt MAX( timestamp ) FROM my_table
请注意,此子查询不限制基于的任何行,
user_2而是询问 整个表中 的最大时间戳是多少。该最大时间戳是上表中的第一个时间戳:(用户_1 =
23,用户_2 = 25,时间戳= 2012-08-10 22:00:00)。
因此,让我们将其插入顶级查询:
- 从
my_table
…中选择一些东西 - 其中user_2 = 22
- 和时间戳= 2012-08-10 22:00:00
- 限制1
…您会看到没有这样的行。



