Below are examples of using SQL to return the last day of the month across various DBMSs.
This could be the last day of the current month, or the last day of a month based on a given date.
Continue readingBelow are examples of using SQL to return the last day of the month across various DBMSs.
This could be the last day of the current month, or the last day of a month based on a given date.
Continue readingSome DBMSs have an NVL2()
function that allows us to replace a value with another value, the new value being determined by whether or not the initial value is null.
It’s similar to the NVL()
function, except that NVL2()
accepts exactly three arguments. This allows us to specify a different value to return in the event the first argument is not null.
In contrast, with the NVL()
function, some DBMSs accept only two arguments (which makes the function a synonym for the IFNULL()
function) while others accept an unlimited number of arguments (which makes it a synonym for the COALESCE()
function).
Some DBMSs provide an NVL()
function, which can be used when working with potentially NULL values. The function allows us to replace any NULL values with another value.
Here are examples of using SQL to return duplicate rows when those rows have a primary key or other unique identifier column.
These queries work in most of the major RDBMSs, including SQL Server, Oracle, MySQL, MariaDB, PostgreSQL, and SQLite.
Continue readingMost RDBMSs provide at least a few ways to return rows that contain lowercase characters. Here are some options available in the major RDBMSs.
Continue readingHere’s an example of using SQL to find duplicate rows in a database table. This technique can be used in most of the major RDBMSs, including SQL Server, Oracle, MySQL, MariaDB, PostgreSQL, and SQLite.
Continue readingHere are examples of converting a Unix timestamp to a date/time value in some of the major RDBMSs.
The Unix timestamp (also known as Unix Epoch time, Unix time, or POSIX time) is the number of seconds that have elapsed since 00:00:00 Thursday, 1 January 1970, Coordinated Universal Time (UTC).
Continue readingAlphanumeric characters are alphabetic characters and numeric characters.
Below are examples of using SQL to return rows that contain only alphanumeric characters.
Continue readingSome RDBMSs provide an ISNULL()
function that can be used when dealing with potentially null values.
MySQL, MariaDB, and Oracle Database each have an ISNULL()
function that returns 1
if its argument is null
, and 0
if it’s not.
SQL Server also has an ISNULL()
function, but it works differently. It works more like how the IFNULL()
function works in some other RDBMSs.
Other RDBMSs, such as PostgreSQL and SQLite don’t include an ISNULL()
function, but they do support the IS NULL
predicate (as do the other RDBMSs).
In MariaDB, we can use the CASE
operator to compare a list of conditions and return a different result depending on which condition (if any) is matched.
The CASE
expression is included in the SQL standard (ISO/IEC 9075), and most major RDBMSs support it.
MariaDB also has the CASE
statement, which is slightly different to the CASE
operator. This article is about the CASE
operator.