从数据库中只找到一个小于条件的条目

find only one entry from database with less than condition

我只需要从数据库中找到一个小于其他行的条目

我已经写了这个查询,除了这个还有其他方法吗?

SELECT * 
FROM  users 
WHERE birthdate < 1420239600

它将return所有生日小于1320239600的用户 但我只需要显示一行 1320239599 而不是 1 到 1320239599

编辑

SELECT * FROM USERS
WHERE birthdate < 13
ORDER BY birthdate DESC
LIMIT 1;

它 returns 1 因为它在所有人中较少但要求是它应该 return 12

MYSQL

SELECT * 
FROM  users 
WHERE birthdate < 1420239600
ORDER BY birthdate DESC
LIMIT 1

MSSQL

SELECT TOP 1 * 
FROM  users 
WHERE birthdate < 1420239600
ORDER BY birthdate DESC

这将 select 第一个条目

我认为最安全的选择是这样的:

SELECT * FROM USERS
WHERE birthdate < 1320239600
ORDER BY birthdate DESC
LIMIT 1;

你用错了小于运算符。 Arijit 的答案只对 MS SQL Server 或 MS Access 有效,这个使用 ORDER BY 和 LIMIT 的语句在 MySQL 中是等价的。

改用这个:

SELECT * 
FROM users
WHERE birthdate = (SELECT MIN(birthdate) FROM users) LIMIT 1;