I have the following data in a MySQL table called info:
chapter | section
3 | 0
3 | 1
3 | 2
3 | 3
4 | 0
5 | 0
I would like to delete the row for chapter = n, but only when there is no section> 0 for the same chapter. Thus, chapter 3 cannot be deleted if chapters 4 and 5 can be deleted. I know the following does not work:
DELETE info WHERE chapter = 3 AND NOT EXISTS (SELECT * FROM info WHERE chapter = 3 AND section>0);
The same table is used twice in the instruction. So what is the easiest way to achieve my goal?
source
share