我试图保留最近的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);
}
http://stackoverflow.com/questions/578867/sql-query-delete-all-records-from-the-table-除了 - latest-n – user20232359723568423357842364
+1,为获胜的子查询。 – PlantTheIdea
你真的需要删除它们吗? – andrewsi