Is there a way to use one query instead of two to check if a row is already in there, overwrite it (UPDATE) and if it's not there, push it in (INSERT)?
And if I need 2 queries, which is the most efficient way to know if a row already exists in the table?
SQL doesn't have any IF THEN ELSE statements. No conditional code.
So to answer your first question. No.
Second Question: Just query it. Then do an IF variable (results) exists statement.
That's what I normally do, but too bad if there is no better way!
In MySQL, yes there is!!!!
REPLACE works exactly like INSERT, except that if an old record in the table has the same value as a new record on a unique index,the old record is deleted before the new record is inserted.
I think Son's questiuon is coming from not knowing the unique index,
if he knows unique index (it means he knows record in the table) then
he will update
he will insert
I was going along the lines of member registration. I don't think he wants to delete the old value if it is the same as the submitted value, if so he'd just use an update query and woulda never had to ask.
Oh yeah, that REPLACE is exactly what I needed :)
Thank you all guys and sorry for any misunderstanding.