I want to add a constant string to all result of one column. Here is my table:
// mytable
id | name
----|--------
1 | jack
2 | peter
3 | ali
I want this output:
select name from mytable order by id;
Your name: jack
Your name: peter
Your name: ali
As you see, I have combined all results of name column with this string: Your name:. I can do that like this:
... CONCAT('Your name: ', name) ...
Now I want to know, is there any approach else? (something like combining by + in MySQL)
CONCAT is the default way to do string concatenation. + is arithemtic operator and when you try:
SELECT 'a' + 'b' -- you will get 0, because of implicit cast to number
There is also CONCAT_WS():
SELECT CONCAT_WS(SPACE(1), 'Your name:','Bob') AS result
SqlFiddleDemo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With