Page 1 of 1

doing an update if exists

Posted: Mon Aug 21, 2006 8:25 pm
by GeXus
Is there a way in mysql to check if a record exists and if so, then do an update, if not, do an insert statement.

Posted: Mon Aug 21, 2006 8:26 pm
by feyd

Code: Select all

REPLACE...

Posted: Mon Aug 21, 2006 8:34 pm
by GeXus
Wicked.. thanks!

Posted: Mon Aug 21, 2006 9:51 pm
by GeXus
This actually does not seem to work.. I probably did not explain well, or maybe I did the replace wrong...

table: favorites
columns:
user_id
fav_1
fav_1_desc
fav_2
fav_2_desc
fav_3
fav_3_desc

It's posible that the fields could be either empty or not.

Posted: Mon Aug 21, 2006 9:54 pm
by GeXus
Ok, I think i figured out what ill do.. basically I can always insert one row for the user_id, without any data, then just do updates to the null columns.