Database Reference
In-Depth Information
Input
SELECT Concat(vend_name, ' (', vend_country, ')')
FROM vendors
ORDER BY vend_name;
Output
+--------------------------------------------+
| Concat(vend_name, ' (', vend_country, ')') |
+--------------------------------------------+
| ACME (USA) |
| Anvils R Us (USA) |
| Furball Inc. (USA) |
| Jet Set (England) |
| Jouets Et Ours (France) |
| LT Supplies (USA) |
+--------------------------------------------+
Analysis
Concat() concatenates strings, appending them to each other to create one
bigger string. Concat() requires one or more values to be specified, each
separated by commas. The previous SELECT statements concatenate four
elements:
The name stored in the vend_name column
A string containing a space and an open parenthesis
The state stored in the vend_country column
A string containing the close parenthesis
As you can see in the output shown previously, the SELECT statement returns
a single column (a calculated field) containing all four of these elements as
one unit.
Back in Chapter 8, “Using Wildcard Filtering,” I mentioned the need to trim
data so as to remove any trailing spaces. This can be done using the MariaDB
RTrim() function, as follows:
Input
SELECT Concat(RTrim(vend_name), ' (', RTrim(vend_country), ')')
FROM vendors
ORDER BY vend_name;
 
Search WWH ::




Custom Search