gpt4 book ai didi

mysql - 唯一键和替换语句

转载 作者:可可西里 更新时间:2023-11-01 08:41:36 25 4
gpt4 key购买 nike

我在同时添加多行时遇到问题我有一个 mysql 表,其中替换相同 id 的多行

假设我有 2 列1)offer_id2)类别通过使用 php 脚本,我每天都在替换所有行,所以我为 offer_id 和类别添加了唯一键但问题是,当有两个值包含1) offer_id=2 和 categories = ecomm2) offer_id=2 and categories = market

我的查询将按如下方式运行

REPLACE INTO `affiliate_offer_get_categories_icube` (`offer_id`, `net_provider`, `categories`) VALUES 
(2, 'icube', 'Marketplace');

REPLACE INTO `affiliate_offer_get_categories_icube` (`offer_id`, `net_provider`, `categories`) VALUES
(2, 'icube', 'Ecoommerce');

在上面的语句中,我必须添加两行相同的“offer_id”但不同的“类别”。但我只得到一行结果(我必须添加两个类别的值。)

最佳答案

听起来您需要唯一索引来跨越两列。删除您拥有的唯一索引并创建一个新索引

CREATE INDEX idx_whatever_name ON your_tablename (offer_id, categories);

关于mysql - 唯一键和替换语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33078278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com