[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2014-03-25
2
Medium Priority
?
853 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
ste5an earned 1500 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

650 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