From: Date: December 28 2005 4:47pm Subject: RE: update or insert if necessary? List-Archive: http://lists.mysql.com/mysql/193283 Message-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable You should read http://dev.mysql.com/doc/refman/4.1/en/insert.html=20 and maybe http://dev.mysql.com/doc/refman/4.1/en/replace.html > -----Original Message----- > From: steve [mailto:networks1@stripped]=20 > Sent: Wednesday, December 28, 2005 8:57 AM > To: mysql@stripped > Subject: update or insert if necessary? >=20 > I have a situation where I need to update a record for a=20 > given key in a MySQL table, but insert a record if the key=20 > doesn't exist. I could do this by doing a SELECT on the key,=20 > then doing an UPDATE if anything comes back, or and INSERT=20 > otherwise. This seems rather clunky though, and I'm=20 > wondering if there is anything like and "up-sert" command, or=20 > at least a preferred way of doing this operation. >=20 > TIA....Steve >=20 INFORMATION IN THIS MESSAGE, INCLUDING ANY ATTACHMENTS, IS INTENDED FOR T= HE PERSONAL AND CONFIDENTIAL USE OF THE INTENDED RECIPIENT(S) NAMED ABOVE= =2E If you are not an intended recipient of this message, or an agent res= ponsible for delivering it to an intended recipient, you are hereby notif= ied that you have received this message in error, and that any review, di= ssemination, distribution, or copying of this message is strictly prohibi= ted. If you received this message in error, please notify the sender imme= diately, delete the message, and return any hard copy print-outs.=0A=0ATh= is message has been scanned for viruses by McAfee's Groupshield.