我有一个mysql表,其中列是:
id, date, sold, rev
我喜欢将行放到date column = some date
,我想删除该行中的所有行,直到表的末尾。我想到的伪代码是这样的:
$date = specific date;
$conn->prepare (select id from table where date = $date)
while (id is not last)
{
$conn->delete (current id from table);
}
答案 0 :(得分:1)
在我看来,我会用
"DELETE FROM table_name WHERE date != $date"
或者您想要从该日期删除到表格的末尾,前提是日期是排列顺序,如降序或升序,您可以使用
"DELETE FROM table_name WHERE date >= $date"
或
"DELETE FROM table_name WHERE date <= $date"
答案 1 :(得分:0)
mysql中的Id以增量顺序的形式插入。因此,您可以通过以下方式选择所需的ID:
select id from table where date = $date;
一旦你得到id(假设在变量$ id中),然后执行查询:
delete from table_name where id >= $id;
它会从所需的行中删除表格末尾的所有行。 也可以通过提供日期条件来删除它(仅当您确定按增量顺序插入日期时):
delete from table_name where date >= $date;