2

I want to delete a row with minimum value of a particular field from a table if number of records less than 5;

1 Answer 1

6

You can do this with sub-selects for the aggregate min and count functions:

DELETE FROM the_table WHERE
  the_field = (SELECT min(the_field) FROM the_table)
  AND (SELECT count(*) FROM the_table) < 5;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.