我为审计线索做了一个表。
CREATE TABLE IF NOT EXISTS `audit_trail_timer` (
`_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`remaining_duration` varchar(50) NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`_id`)
)
现在我想选择一个时间戳是最新的行。
$query = select * from audit_trail_timer where user_id='$id' and timestamp='';
答案 0 :(得分:3)
SELECT top 1 * FROM audit_trail_timer WHERE user_id ='$ id' 订购TIMESTAMP DESC;
答案 1 :(得分:1)
试试这个,
SELECT * FROM audit_trail_timer WHERE user_id='$id'
ORDER BY TIMESTAMP DESC LIMIT 1
答案 2 :(得分:1)
try this
SELECT * FROM audit_trail_timer WHERE user_id='$id'
ORDER BY TIMESTAMP DESC LIMIT 1
答案 3 :(得分:1)
使用
SELECT *
FROM audit_trail_timer
WHERE user_id = '$id'
ORDER BY `timestamp` DESC
LIMIT 1
timestamp
是保留关键字