Code: Select all
REPLACE INTO dealinfo (`site`, `city`, `deal`, `afflink`) VALUES ('buy', 'Halifax', '$title', 'test') WHERE `id` = '21';Moderator: General Moderators
Code: Select all
REPLACE INTO dealinfo (`site`, `city`, `deal`, `afflink`) VALUES ('buy', 'Halifax', '$title', 'test') WHERE `id` = '21';Ok, that makes sense.mikosiko wrote:WHERE is not part of the REPLACE syntax
http://dev.mysql.com/doc/refman/5.0/en/replace.html
and not being part of SQL standard you better use INSERT instead that will make your code more portable.. alternative... use INSERT...ON DUPLICATE KEY UPDATE
Code: Select all
INSERT dealinfo (`site`, `city`, `deal`, `afflink`) VALUES ('buy', 'Halifax', '$title', 'test') ON DUPLICATE KEY UPDATE `id` = '21' Basically I have a script that runs and scans an RSS feed for the latest feed headline. The headline is written to a database with unique id and info (Site, City, Headline, Afflink(currently hardcoded, working on lookup table).Eran wrote:The unique column needs to be a part of the INSERT columns. Why don't you tell us simply what you are trying to achieve?
Code: Select all
INSERT INTO dealinfo (`id`,`site`, `city`, `deal`, `afflink`) VALUES (21,'buy', 'Halifax', '$title', 'test')
ON DUPLICATE KEY UPDATE `site`=VALUES(`site`),`city`=VALUES(`city`),`deal`=VALUES(`deal`),`afflink`=VALUES(`afflink`)You are a master! Thank you!Eran wrote:The unique column (id) is one of the insert columns. Since it already exists (duplicate key) the values in the UPDATE part will be updatedCode: Select all
INSERT INTO dealinfo (`id`,`site`, `city`, `deal`, `afflink`) VALUES (21,'buy', 'Halifax', '$title', 'test') ON DUPLICATE KEY UPDATE `site`=VALUES(`site`),`city`=VALUES(`city`),`deal`=VALUES(`deal`),`afflink`=VALUES(`afflink`)