views:

28

answers:

2

Is there a way in MySQL to concatenate text to values using a SELECT statement? (like in Oracle)

For example, in Oracle you can write something like this:

SQL> select 'The Year is '|| year, 'The month is '|| month from time where rownum < 2;

'THEYEARIS'||YEAR
----------------------------------------------------
'THEMONTHIS'||MONTH
-----------------------------------------------------
The Year is 2009
The month is 1
+2  A: 
SELECT Concat(vend_name, ' (', vend_country, ')')
FROM vendors
ORDER BY vend_name;

Read this tutorial:

http://www.brainbell.com/tutorials/MySQL/Concatenating_Fields.htm

Trufa
+1 Nice answer and reference.
JoshD
very nice! Thank you guys!
jda6one9
@jda6one9 No problem!!
Trufa
+2  A: 

There is a CONCAT function in mysql.

select concat('The Year is ', year), concat('The month is ', month) from time where rownum < 2;
JoshD
@JoshD - thanks for the tip!
jda6one9