我正在尝试将 10 个最新条目保留在我的数据库中并删除较旧的条目。我试过DELETE FROM people ORDER BY id DESC LIMIT $excess
了,但它只是删除了前 10 个条目。
$query = "SELECT * FROM people";
$result = mysqli_query($conn, $query);
$count = mysqli_num_rows($result);
if ($count > 10) {
$excess = $count - 10;
$query = "DELETE FROM people WHERE id IN(SELECT id FROM people ORDER BY id DESC LIMIT '$excess')";
mysqli_query($conn, $query);
}