我如何使用表中的行数作为mysql中的限制值

I am trying get the latest 10 rows and delete remaining rows of a particular id with one query.

Here is my query:

DELETE 
FROM `courses` 
WHERE customer_id = 11 
ORDER BY id ASC LIMIT (SELECT COUNT(*) FROM `courses` WHERE customer_id = 11);

Please anyone help me to recognize the error in this query.

Thanks.

i found the solution, here is the query :

$sql1="DELETE FROM `courses` WHERE customer_id =11 AND id NOT IN (SELECT id
  FROM (SELECT id FROM `courses` WHERE customer_id =11 ORDER BY id DESC LIMIT 10) AS foo)";
$conn->query($sql1);

By above query, we get the latest 10 rows and delete the remaining rows of a particular id.