php - MySQL - decrement int value, delete row if int reaches 0 -


i'm trying find query exact opposite of this:

insert wordstable (word, counter)  values('$word', 1) on duplicate key update counter = counter + 1 

(this sql fine. "word" set unique , everything)

so, basically, decrement counter, if counter reaches 0, delete whole row. i'm thinking might i've no clue if valid syntax:

update wordstable set counter = counter - 1 id='$deletethisword' if (occ = 0) (     delete *     wordstable     id='$deletethisword' ) 

is there nice clean way this?

thanks!

you need 2 queries:

delete wordstable id='$deletethisword' , counter = 1;  update wordstable set counter = counter - 1 id = '$deletethisword' 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -