mysql - INSERT new row or DELETE old row IF it already exists -


i need optimize/implement mysql query wich following:

i need store if user marked item seen, , create seen/unseen button, delete correspondent row on database if exists (is marked seen) or insert new row if not (is not marked).

it means, need mysql query that:

    delete table userid = ? , itemid = ? 

or that

    insert table (userid, itemid) values (?,?) 

depending on if row exists or not.

i it's easy doing php , checking number of rows of select before insert or delete doing optimized can.

you can use stored procedure select , delete if exists or insert. easier left data there , update seen/unseen on duplicate key update.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -