Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I want to delete a row with minimum value of a particular field from a table if number of records less than 5;
You can do this with sub-selects for the aggregate min and count functions:
min
count
DELETE FROM the_table WHERE the_field = (SELECT min(the_field) FROM the_table) AND (SELECT count(*) FROM the_table) < 5;
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.