0

On my web page there is no insert or update but already to this I'm getting this error:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0-Bekoo-2449.10' for key 'group_key'

This is surprising because the web page does not modify any rows, and the Product table does not have a group_key column or key.

My query :

SELECT Product._like,
       comment_count,
       title,
       price_lower,
       price,image,
       AffiliateOffers.name,
       p‌​‌​ayout_yuzde,
       payout_nakit,
       payout_type,
       xml_id,
       brand,model,
       currency,url,
       Product.af‌​f_‌​id,
       Product.offer_id,
       pb_share_1,
       pb_share_2,
       pb_share_1_payda,
       pb_share_2_payda,
       A‌​ffil‌​iateOffers.seo_title,
       afo_offer_id,
       r_category,
       seo_description 
FROM Product 
inner Join AffiliateOffers on Product.aff_id = AffiliateOffers.af_id 
      AND Product.offer_id = AffiliateOffers.af_offer_id 
where Product.status = 1 
    and Product.aff_id = 1 
    and Product.offer_id = 1290

and my table structure :

` CREATE TABLE `_product` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `xml_id` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `aff_id` int(11) NOT NULL,
  `offer_id` int(11) NOT NULL,
  `r_category` int(11) NOT NULL,
  `category_id` int(11) NOT NULL,
  `category_id1` int(11) NOT NULL,
  `category_id2` int(11) NOT NULL,
  `category_id3` int(11) NOT NULL,
  `brand` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
  `model` varchar(75) COLLATE utf8_unicode_ci DEFAULT NULL,
  `title` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  `description_1` mediumtext COLLATE utf8_unicode_ci,
  `price` decimal(18,2) NOT NULL,
  `price_lower` decimal(18,2) NOT NULL,
  `percentage_lower` int(11) NOT NULL,
  `image` mediumtext COLLATE utf8_unicode_ci NOT NULL,
  `url` text COLLATE utf8_unicode_ci,
  `feature` tinyint(4) NOT NULL,
  `city` varchar(250) COLLATE utf8_unicode_ci DEFAULT NULL,
  `sex` tinyint(4) NOT NULL,
  `stock` tinyint(4) NOT NULL,
  `start_date` int(25) NOT NULL,
  `finish_date` int(25) NOT NULL,
  `update_date` int(25) NOT NULL,
  `status` tinyint(4) NOT NULL DEFAULT '1',
  `hit` int(11) NOT NULL DEFAULT '1',
  `_like` int(11) NOT NULL DEFAULT '0',
  `comment_count` int(11) DEFAULT NULL,
  `like_count` int(11) DEFAULT NULL,
  `lastlike_time` int(25) DEFAULT NULL,
  `visit_count` int(11) DEFAULT NULL,
  `lastvisit_count` int(25) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `xml_id` (`xml_id`),
  KEY `lastlike_time` (`lastlike_time`),
  KEY `offer_id` (`offer_id`),
  KEY `r_category` (`r_category`),
  KEY `status` (`status`)
) ENGINE=MyISAM AUTO_INCREMENT=3816867 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci`

Why am I getting this error?

Jeremy Smyth
  • 23,270
  • 2
  • 52
  • 65
Muhammet Arslan
  • 975
  • 1
  • 9
  • 33
  • http://stackoverflow.com/questions/10044062/sqlstate23000-integrity-constraint-violation-1062-duplicate-entry-1922-1-f – Nagaraj S Jan 17 '14 at 11:49
  • i add an edit. there is no "group_key" key. – Muhammet Arslan Jan 17 '14 at 11:53
  • (primary key or unique index) with 3 unique fields. there must be a write operation somewhere. maybe a trigger ? – aconrad Jan 17 '14 at 11:54
  • On my table there is a key only and its primary (ID ) . No there are no write operation , and not trigger – Muhammet Arslan Jan 17 '14 at 11:56
  • Just post: your table structure (full `SHOW CREATE TABLE`) and your query – Alma Do Jan 17 '14 at 11:57
  • My query : `SELECT Product._like,comment_count,title,price_lower,price,image,AffiliateOffers.name,p‌​ayout_yuzde,payout_nakit,payout_type,xml_id,brand,model,currency,url,Product.aff_‌​id,Product.offer_id,pb_share_1,pb_share_2,pb_share_1_payda,pb_share_2_payda,Affil‌​iateOffers.seo_title,afo_offer_id,r_category,seo_description FROM Product inner Join AffiliateOffers on Product.aff_id = AffiliateOffers.af_id AND Product.offer_id = AffiliateOffers.af_offer_id where Product.status = 1 and Product.aff_id = '1' and Product.offer_id = '1290'` – Muhammet Arslan Jan 17 '14 at 12:00
  • Put things like the query and table structure into the question, rather than post them as a comment or answer. – Jeremy Smyth Jan 17 '14 at 12:02
  • Do you have any triggers? Maybe the query is triggering an update on another table? – Spudley Jan 17 '14 at 12:42

2 Answers2

2

Unless you say otherwise, group_key is an internal field used by MySQL when aggregating things so you won't find it in your own tables or view. A duplicate entry error in there means you've got some sort of problem with your aggregation.

Have a look at any GROUP BY statements you're using, and ensure you've got their syntax correct, particularly in any aggregate functions and group expressions.

Jeremy Smyth
  • 23,270
  • 2
  • 52
  • 65
  • Are you using aggregate functions like `DISTINCT` or `MAX` or `AVG`? – Jeremy Smyth Jan 17 '14 at 11:55
  • No , look my query. `SELECT Product._like,comment_count,title,price_lower,price,image,AffiliateOffers.name,payout_yuzde,payout_nakit,payout_type,xml_id,brand,model,currency,url,Product.aff_id,Product.offer_id,pb_share_1,pb_share_2,pb_share_1_payda,pb_share_2_payda,AffiliateOffers.seo_title,afo_offer_id,r_category,seo_description FROM Product inner Join AffiliateOffers on Product.aff_id = AffiliateOffers.af_id AND Product.offer_id = AffiliateOffers.af_offer_id where Product.status = 1 and Product.aff_id = '1' and Product.offer_id = '1290'` – Muhammet Arslan Jan 17 '14 at 11:56
  • `offer_id` and `aff_id` are `INT` types, so you shouldn't compare them against strings as you are with `= '1290'` and `= '1'` – Jeremy Smyth Jan 17 '14 at 12:04
  • I did it but i think its not about the error ? But thanks again – Muhammet Arslan Jan 17 '14 at 12:06
  • i found the problem , its about the distinct . I want to get group by or distinct the brand,price and r_category but i couldnt do it with group by because its so slows. query : `SELECT distinct r_category as r_category,brand as brand,price as price FROM Product where Product.status = 1 and Product.aff_id = 1 and Product.offer_id = 1290` – Muhammet Arslan Jan 17 '14 at 12:11
0

In Phpmyadmin you have to truncate all the logtables. That should fix it.

I ran into the same problem, i was forgotten to clear the visitor and online log. Both of the tables are generate a log/id for the user ( thats where the XXX for stands ) If you truncate both of the tables it will fix this problem.

user1629905
  • 61
  • 1
  • 1
  • 7