I have table with fields
name quantity expiry
a 2 14/12/2012
b 3 13/2/2013
If name exist and quantity is 0 than query will work as update query other wise work as insert query . More than one row can exist with same name but will have different expiry.
You’re looking for
INSERT ... ON DUPLICATE KEY UPDATE. See the documentation.EDIT: I’m not sure if the “if quantity is 0” part can be accomplished with that, though, so this might not fully answer your question.