删除上一个时间戳的行?

时间:2013-11-06 06:36:27

标签: php mysql delete-row

我正在尝试使用此SQL查询从具有特定成员的行中删除具有最新日期的表中的行。

此查询选择要删除的正确行:

SELECT *
FROM Swears
WHERE Date = ( 
  SELECT MAX(DATE) 
  FROM Swears
  WHERE Member = 36)

但是这个查询不会删除该行。

DELETE
  FROM Swears
  WHERE Date = ( 
    SELECT MAX(DATE) 
    FROM Swears
    WHERE Member = 36)

2 个答案:

答案 0 :(得分:4)

DELETE
FROM Swears
WHERE Member = 36
ORDER BY Date DESC 
LIMIT 1; -- for the first row

答案 1 :(得分:0)

DELETE FROM <table_name>
where <member_column> = <member_value>
ORDER BY Date DESC LIMIT 1