Solved

How to retrieve distinct values from concat field in a group by query

Posted on 2014-03-25
2
775 Views
Last Modified: 2014-03-25
Hi
Assuming the following rows in my table:
ID , Field1, Field2, ConcatField
1  , "test",    3,    "a,b"
2  , "tttt",     2,    "a,c,d"
3  , "test",   8,    "a"
4,  "test",   1,    "d"

Open in new window


I would like to run a query grouped by field1 and showing count(ID), sum(field2) and a field with all values in the concatfield, i.e
Field1, Count, Sum, ConcatField
"test",   3,  12,   "a,b,d"
"tttt",  1,  2,    "a,c,d"

Open in new window


How can i do that?
Thanks
Jaime
0
Comment
Question by:GreatSolutions
2 Comments
 
LVL 33

Accepted Solution

by:
ste5an earned 500 total points
ID: 39953410
Use GROUP_CONCAT(), e.g.
SELECT 
  Field1,
  COUNT(*)
  SUM(Field2)
  GROUP_CONCAT(ConcatField)
FROM your_table
GROUP BY Field1;

Open in new window

0
 
LVL 2

Author Comment

by:GreatSolutions
ID: 39953537
Many thanks for the fast response!
It gave me duplicates inside the field, but group_concat ( distinct ConcatField ) did the trick!

Jaime
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now