I don't know concatenation operator for MySQL.
I have tried this code for concatenation:
SELECT vend_name || ' (' || vend_country || ')' FROM Vendors ORDER BY vend_name;
But it didn't work. Which operator should I use to concatenate strings?
MySQL CONCAT() function is used to add two or more strings. There may be one or more arguments. Returns the string that results from concatenating the arguments. Returns a nonbinary string, if all arguments are nonbinary strings.
That said, if you want to treat || as a string concatenation operator (same as CONCAT() ) rather than as a synonym for OR in MySQL, you can set the PIPES_AS_CONCAT SQL mode. Better answer, explains that MySQL doesn't use concatenation operators.
CONCAT() function in MySQL is used to concatenating the given arguments. It may have one or more arguments. If all arguments are nonbinary strings, the result is a nonbinary string. If the arguments include any binary strings, the result is a binary string.
The concatenation operator is a binary operator, whose syntax is shown in the general diagram for an SQL Expression. You can use the concatenation operator ( || ) to concatenate two expressions that evaluate to character data types or to numeric data types.
||
is the ANSI standard string concatenation operator, supported by most databases (notably not MS SQL Server). MySQL also supports it, but you have to SET sql_mode='PIPES_AS_CONCAT';
or SET sql_mode='ANSI';
first.
You were using ORACLE type of concatenation. MySQL's Should be
SELECT CONCAT(vend_name, '(', vend_country, ')')
Call the CONCAT()
function and separate your values with commas.
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