MariaDB has a GROUP_CONCAT() function that enables us to return columns from a query as a delimited list.
MariaDB
8 Ways to Add an Hour to a Datetime in MariaDB
There are many ways to perform date arithmetic in MariaDB. This includes adding or subtracting a certain number of a given date part from a date or datetime value.
In this article, I present 8 ways to add an hour to a datetime value in MariaDB.
How to Format Numbers in MariaDB
MariaDB has the FORMAT() function, which formats a number based on the given format string.
It returns the number as a formatted string, with thousands and decimal separators in the appropriate position and rounds the result to the specified decimal position.
You can optionally specify a locale value to format numbers to the pattern appropriate for the given region.
How to Concatenate Strings in SQL
Most of the major RDBMSs provide several options for concatenating two or more strings.
- There’s the
CONCAT()function, which concatenates its arguments. - There’s also a
CONCAT_WS()that allows you to specify a separator that separates the concatenated strings. - And there’s also a string concatenation operator, which allows us to concatenate its operands.
Below are examples of each method.
How to Get the Day, Month, and Year from a Date in SQL
Most of the major RDBMSs have functions that enable us to extract the day, month, and year from datetime values.
Some RDBMSs provide multiple ways to do this, and others are more limited. Below are examples of extracting the day, month, and year from date values in some of the most popular RDBMSs.
2 Ways to Concatenate Strings and Numbers in MariaDB
Here are two ways to concatenate strings and numbers in MariaDB:
- Use the
CONCAT()function, which concatenates its arguments. - Use the pipe concatenation operator (
||), which concatenates its operands.
Below are examples of each.
7 Options for Enabling Pipes (||) as the Concatenation Operator in MariaDB
By default, two pipe characters (||) are treated as a logical OR operator in MariaDB. However, you can change this behaviour if you like.
You can update your sql_mode to include the PIPES_AS_CONCAT option, in which case two pipes will be treated as a concatenation operator.
There are quite a few ways to add this option to your sql_mode. You can add it explicitly. Or you can set your sql_mode to an option that sets it implicitly.
I run through these options below.