I’m building a simple search table (eventually using jquery Datatables) for our knowledgebase. I’m able to return all of the information I need , but I am getting “duplicate” rows when one row is linked to more than one of our products.
For example, solution # 377 pertains to Product 1, Product 2 and Product 3 in our DB. When I run my query, I get the following results:
ID Product Description
377 Product1 Description xyz
377 Product2 Description xyz
377 Product3 Description xyz
The only difference among the three rows is the ‘Product’ Column. Is there a way to return this data as:
ID Product Description
377 Product1, Product2, Product3 Description xyz
My query:
select kb.kbarticleid as ID,
kbc.title as Product,
kb.subject as Subject,
kbd.contentstext as Contents
from swkbarticles kb
inner join swkbarticledata kbd on kb.kbarticleid = kbd.kbarticleid
inner join swkbarticlelinks kbl on kb.kbarticleid = kbl.kbarticleid
inner join swkbcategories kbc on kbl.linktypeid = kbc.kbcategoryid
I took your query, put it in a subquery, collected all products as a CSV string, and ran a GROUP BY
My make no claims on performance to my quick-and-dirty answer. I do not know if the subject was the description or which table has the description column.
Assuming your query works, I made it a subquery and returned just ID,Description,and Products. I then take those three columns and call the GROUP_CONCAT function. That function will combine all products sharing the same GROUP BY elements.
In principle, that will produce the output for ID 377 you asked for.