Deleting a row based on the max value?

Use: DELETE FROM TABLE t1 JOIN (SELECT MAX(jobPositonId) AS max_id FROM TABLE) t2 WHERE t1. JobPositonId = t2. Max_id Mind that all the rows with that jobPositonId value will be removed, if there are duplicates The stupid part about the 1093 error is that you can get around it by placing a subquery between the self reference: DELETE FROM TABLE WHERE jobPositonId = (SELECT x.Id FROM (SELECT MAX(t. JobPostionId) AS id FROM TABLE t) x) Explanation MySQL is only checking, when using UPDATE & DELETE statements, if the there's a first level subquery to the same table that is being updated.

That's why putting it in a second level (or deeper) subquery alternative works. But it's only checking subqueries - the JOIN syntax is logically equivalent, but doesn't trigger the error.

Use: DELETE FROM TABLE t1 JOIN (SELECT MAX(jobPositonId) AS max_id FROM TABLE) t2 WHERE t1. JobPositonId = t2. Max_id Mind that all the rows with that jobPositonId value will be removed, if there are duplicates. The stupid part about the 1093 error is that you can get around it by placing a subquery between the self reference: DELETE FROM TABLE WHERE jobPositonId = (SELECT x.

Id FROM (SELECT MAX(t. JobPostionId) AS id FROM TABLE t) x) Explanation MySQL is only checking, when using UPDATE & DELETE statements, if the there's a first level subquery to the same table that is being updated. That's why putting it in a second level (or deeper) subquery alternative works.

But it's only checking subqueries - the JOIN syntax is logically equivalent, but doesn't trigger the error.

– Robert de Klerk Sep 1 '10 at 18:51 @Robert de Klerk: See update to my answer to explain the behaviour. – OMG Ponies Sep 1 '10 at 19:11.

DELETE FROM table ORDER BY jobPositonId DESC LIMIT 1.

DELETE FROM `table_name` WHERE jobPositonId = (select max(jobPostionId) from `table_name` limit 1) OR DELETE FROM `table_name` WHERE jobPositonId IN (select max(jobPostionId) from `table_name` limit 1).

– Thomas Sep 1 '10 at 18:31 Same error MySQL error 1093 - can't specify target table for update in FROM clause – Robert de Klerk Sep 1 '10 at 18:46 Sorry for my bad info, I didn't have time to test it, +1 for Konerak, he post the correct answer ;) – el_quick Sep 1 '10 at 19:51.

Mind that all the rows with that jobPositonId value will be removed, if there are duplicates. MySQL is only checking, when using UPDATE & DELETE statements, if the there's a first level subquery to the same table that is being updated. That's why putting it in a second level (or deeper) subquery alternative works.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions