0

I am making a price comparing website. I have data from different stores, but I could not find any way to map similar products to single product.

I have a table 'product' like this .

  id       title                                               brandName    
|  8986 | Samsung Galaxy Ace                                 | Samsung   |       1 |
|  8983 | Samsung Galaxy Ace                                 | Samsung   |       1 |
|  6048 | Samsung Galaxy Ace                                 | Samsung   |       1 |
|  6109 | Samsung Galaxy Ace                                 | Samsung   |       1 |
|  9840 | Samsung Galaxy Ace Duos                            | Samsung   |       1 |
|  8905 | Samsung Galaxy Ace Duos                            | Samsung   |       1 |
|  9097 | Samsung Galaxy Ace Duos                            | Samsung   |       1 |
|   765 | Samsung galaxy Ace Duos S6802 ( Black)             | Samsung   |       2 |
|   766 | Samsung Galaxy Ace Duos S6802 (Chic White)         | Samsung   |       2 |
| 11880 | Samsung Galaxy Ace NXT                             | Samsung   |       1 |
| 11218 | Samsung Galaxy Ace NXT                             | Samsung   |       1 |
|   323 | Samsung Galaxy Ace Nxt G313H Black                 | Samsung   |       2 |
|   311 | Samsung Galaxy Ace Nxt G313H White                 | Samsung   |       2 |
|  9099 | Samsung Galaxy Ace Plus                            | Samsung   |       1 |
|  1153 | Samsung Galaxy Ace Plus S7500 Dark Blue            | Samsung   |       2 |

Now I want to map similar products; for example I need results like

title                                  brandIDs
Samsung Galaxy Ace             8986 , 8983 , 6048 , 6109
Samsung Galaxy Ace Duos        9840 , 8905 ,9097 ,  765 , 766
Samsung Galaxy Ace NXT         11880 , 11218 , 323 , 311
Samsung Galaxy Ace Plus        9099 , 1153

Is there any programming logic or mysql which can give me desired result? I tried different mysql clause i.e LIKE'%%' but it returns me whole data.

Edit : I also tried to use group by 'title' an it gave me this result but still does not give desired one . Here is the result . I tried this query . SELECT id,title,brandName from product where brandName LIKE '%samsung%' GROUP BY title ORDER BY title

   id       title                       brandName
|  6048 | Samsung Galaxy Ace                                 | Samsung   |
|  8905 | Samsung Galaxy Ace Duos                            | Samsung   |
|   765 | Samsung galaxy Ace Duos S6802 ( Black)             | Samsung   |
|   766 | Samsung Galaxy Ace Duos S6802 (Chic White)         | Samsung   |
| 11218 | Samsung Galaxy Ace NXT                             | Samsung   |
|   323 | Samsung Galaxy Ace Nxt G313H Black                 | Samsung   |
|   311 | Samsung Galaxy Ace Nxt G313H White                 | Samsung   |
|  9099 | Samsung Galaxy Ace Plus                            | Samsung   |
|  1153 | Samsung Galaxy Ace Plus S7500 Dark Blue            | Samsung   |
Deepak Rathore
  • 617
  • 8
  • 25
  • 2
    Possible duplicate of [How to use GROUP BY to concatenate strings in MySQL?](http://stackoverflow.com/questions/149772/how-to-use-group-by-to-concatenate-strings-in-mysql) – Tunaki Oct 12 '15 at 12:20
  • @Tunaki this question is different . your suggested link does not solve my problem , there first two row id's are same . – Deepak Rathore Oct 12 '15 at 12:27
  • It's exactly the same, here its "Title" which is the same. You need to group by title and concat the ids. – Tunaki Oct 12 '15 at 12:31
  • @Tunaki I have edited my question plz have a look . Still i am not able to desired result . – Deepak Rathore Oct 12 '15 at 12:37
  • You did not post the query you used so there's nothing I can do. You should read more carefully the duplicate post. – Tunaki Oct 12 '15 at 12:42
  • @Tunaki i added a query can you plz tell me solution or any thing should i provide here ? – Deepak Rathore Oct 12 '15 at 12:48
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/92046/discussion-between-deepak-rathore-and-tunaki). – Deepak Rathore Oct 12 '15 at 12:48

0 Answers0