Page 1 of 1

SELECT merging several columns from one table

Posted: Wed Mar 07, 2007 5:53 am
by andym01480
I have a query

Code: Select all

SELECT surname,addressname,children, add1,add2,town,county,postcode,phone,mobile,email,email2 FROM address  ORDER BY surname
what I really like is for the fields "add1, add2, town, county, postcode" to be formatted with comma and space and in the result as one field say "address".

How do I do that?

Posted: Wed Mar 07, 2007 7:44 am
by mikeq

Code: Select all

SELECT CONCAT(add1,', ',add2,', ',postcode) AS address.....
something along those lines should do it

Posted: Wed Mar 07, 2007 8:33 am
by onion2k
Better yet...

Code: Select all

select CONCAT_WS(", ", add1, add2, town, county, postcode) AS address FROM table