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
Post a Comment