LaundroMat
01-13-2003, 05:43 PM
Is it possible to create a query that will do an UPDATE or an INSERT depending on certain data already in the database?
Eg I'd like to record a user's vote. If this user hasn't voted already, an INSERT is called for, otherwise an UPDATE. Right now, I'm SELECTing first, checking whether the user's id is already in the votes table, and if yes, my query's an UPDATE, otherwise it's an INSERT.
This needs two hits on the DB however, and I'm someone who likes to limit the amount of DB hits as much as possible.
Eg I'd like to record a user's vote. If this user hasn't voted already, an INSERT is called for, otherwise an UPDATE. Right now, I'm SELECTing first, checking whether the user's id is already in the votes table, and if yes, my query's an UPDATE, otherwise it's an INSERT.
This needs two hits on the DB however, and I'm someone who likes to limit the amount of DB hits as much as possible.