Does replace into have a where clause?

I can see that you have solved your problem, but to answer your original question:

REPLACE INTO does not have a WHERE clause.

The REPLACE INTO syntax works exactly like INSERT INTO except that any old rows with the same primary or unique key is automaticly deleted before the new row is inserted.

This means that instead of a WHERE clause, you should add the primary key to the values beeing replaced to limit your update.

REPLACE INTO myTable (
  myPrimaryKey,
  myColumn1,
  myColumn2
) VALUES (
  100,
  'value1',
  'value2'
);

…will provide the same result as…

UPDATE myTable
SET myColumn1 = 'value1', myColumn2 = 'value2'
WHERE myPrimaryKey = 100;

…or more exactly:

DELETE FROM myTable WHERE myPrimaryKey = 100;
INSERT INTO myTable(
  myPrimaryKey,
  myColumn1,
  myColumn2
) VALUES (
  100,
  'value1',
  'value2'
);

Leave a Comment