parsing cols in query

sacul
sacul used Ask the Experts™
on
Hello Experts,

Is there a away to write a query in mySQL to parse multiple cols into a single string  col?

like "SELECT (col1 + col2 + col3) aliasName from tbl"

Thank you
Zac
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2005

Commented:
That's it. Good practice suggests you always use the optional AS keyword to avoid confusion:
SELECT (col1 + col2 + col3) AS aliasName FROM tbl
Actually in MySQL the + operator will try to add the strings and come up with zero.

SELECT CONCAT(col1, col2, col3, 'literals can go in here too') AS aliasName FROM tbl;

... will do the concatenation.

Author

Commented:
Perfect,

Thank you for the quick answer.
I guess the + sign is trying to do an addition of the strings over a concatenation.

Thank you,
Zac

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial