Jump to content

[SOLVED] Exporting with the SQL Manager: concatenating all customer addresses


Recommended Posts

How might I be able to concatenate all the addresses of a single customer into one field? How should this be modified:

	SELECT CONCAT_WS(' ', g.lastname, g.firstname) AS Customer, g.id_customer AS customerID, CONCAT_WS(' ', ad.address1, ad.address2, 'City:', ad.postcode, ad.city, ad.other, 'Phone:', ad.phone, 'Mobile:', ad.phone_mobile) AS Addresses, gl.name AS group_name, g.email
	FROM  ps_customer g
	LEFT JOIN ps_address ad ON (g.id_customer = ad.id_customer)
	LEFT JOIN ps_group_lang gl ON (g.id_default_group = gl.id_group) AND gl.name LIKE 'club%'
Edited by Beluga (see edit history)
Link to comment
Share on other sites

Here's the correct way:
 

SELECT CONCAT_WS(' ', g.lastname, g.firstname) AS Customer, g.id_customer AS customerID, GROUP_CONCAT(CONCAT_WS(' ', ad.address1, ad.address2, 'City:', ad.postcode, ad.city, ad.other, 'Phone:', ad.phone, 'Mobile:', ad.phone_mobile)) AS Addresses, gl.name AS group_name, g.email
FROM ps_customer g
LEFT JOIN ps_address ad ON (g.id_customer = ad.id_customer)
LEFT JOIN ps_group_lang gl ON (g.id_default_group = gl.id_group) AND gl.name LIKE 'piiri%'
GROUP BY g.id_customer
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...