repeated values with group_concat and joins
i have a little problem with the following Query. It returns multiple values.
Here is the result I'm receiving:
+----+--------------+--------+--------+---------------------+----------+------------------+
| id | company | county | vm | os | products |
sn |
+----+--------------+--------+--------+---------------------+----------+------------------+
| 1 | ABC Corp | USA | VMW | Linux, Linux, Linux | 3 |
A123, B234, A343 |
| 2 | DEF Corp | USA | CIT | Windows | 1 |
I223 |
+----+--------------+--------+--------+---------------------+----------+------------------+
As you can see, the first line shows 3 times Linux, but this should be
only listed once. I've seen that this problem only occurs if the customer
has more than 1 product. I think i have to Group my Query or something
like this, but i don't know how.
Here is my Query:
SELECT
customer.id,
customer.company,
countries.en AS country,
vmenv.name AS vm,
GROUP_CONCAT(operatingsystems.name SEPARATOR ', ') AS os,
COUNT(device2customer.sn) AS products,
GROUP_CONCAT(device2customer.sn SEPARATOR ', ') AS sn
FROM
customer
LEFT JOIN
countries
ON
customer.country = countries.id
LEFT JOIN
vmenv2kunden
ON
vmenv2kunden.customerid = customer.id
LEFT JOIN
vmenv
ON
vmenv2kunden.vmenvnr = vmenv.id
LEFT JOIN
operatingsystems2customer
ON
operatingsystems2customer.customerid = customer.id
LEFT JOIN
operatingsystems
ON
operatingsystems2customer.osnr = operatingsystems.id
LEFT JOIN
device2customer
ON
device2customer.kundenid = customer.id
GROUP BY
customer.id
No comments:
Post a Comment