I get data with multiple columns ( select ), which differ only in one img field. As a result, many duplicates are created.

How to combine the img field?

Just need to get the combined data img.

Now the sample looks like this:

  • fields with the same values
  • img one


  • fields with the same values

  • img other

Then the fields are already different, but the problem of creating duplicates naturally remains.

Table structure:

 `product` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `parent` int(11) DEFAULT '0', `url` varchar(255) DEFAULT NULL, `name` varchar(255) NOT NULL, ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=400005659 ; `product_img` ( `id` int(10) NOT NULL AUTO_INCREMENT, `parent` int(10) unsigned NOT NULL, `name` varchar(255) NOT NULL, PRIMARY KEY (`id`), KEY `parent` (`parent`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=143077 ; 

I am writing a query of the form:

 SELECT product.url, product.name, product_img.name as product_img_name FROM product JOIN product_img ON product_img.parent=product.parent 
  • one
    describe the problem in more detail. show the structure of the tables, the input data and the desired result. Specify at what point you need to do this in a select query, or when inserting new records, or update an existing table. And be sure to specify which database you are using, because requests and approaches to solving a problem can be completely different on different DBMS - Mike
  • Updated, so it should be clearer. - Timur Musharapov
  • @TimurMusharapov "should be clearer" - not by much. Have you carefully read the comment above? - Igor
  • We must understand why this is happening. how it happens in the real world is what the data is based on. if all fields are the same except img, you may need to put these fields in one table, assign them an id, and keep the img list for this record in another table. - Mike
  • 2
    So, the structure is clear and it looks correct. The request will actually select several entries that have a different img field only. The question remains what do you want to receive as a result of the request, what do you mean by "combine img field", if you collect it separated by commas, then you need group_concat ru.stackoverflow.com/questions/491062 - Mike

0