MySQL has an IFNULL()
function that allows us to easily replace NULL values with another value.
Category: DBMS
Database Management Systems
Oracle ISNULL() Equivalent
Most major DBMSs provide us with a function for replacing null values with another value.
But the name of the function tends to differ across DBMSs. For example, SQL Server has an ISNULL()
function, while others (such as MySQL, MariaDB, and SQLite) have an IFNULL()
function for doing the same thing.
However, to confuse matters, MySQL and MariaDB each have an ISNULL()
function that works differently to SQL Server’s function of the same name (MySQL and MariaDB’s implementation only accept a single argument, and return 1
if its null
and 0
if it’s not).
MySQL ISNULL() Explained
In MySQL, the ISNULL()
function enables us to check whether a value is null
or not. If it’s null
, then 1
is returned, otherwise 0
is returned.
2 Ways to Return Non-Numeric Values in SQLite
The following SQLite examples return only those rows that have non-numeric values in a given column.
Continue readingSubtract Weeks from a Date in PostgreSQL
We can use the -
operator to subtract one or more weeks from a date in PostgreSQL.
How IFNULL() Works in MariaDB
In MariaDB, the IFNULL()
function allows us to replace NULL values with another value.
How NVL() Works in MariaDB
From MariaDB 10.3, NVL()
can be used as an alias for the IFNULL()
function. Therefore, both functions enable us to replace NULL values with another value.
MySQL IF() Function Explained
MySQL has an IF()
function that provides a convenient way to perform a simple “IF/ELSE” operation.
It works similar to a basic IF
/ELSE
statement, in that it allows us to check for a condition, and return a different result depending on whether it’s true or not.
More specifically, if the first argument to the IF()
function is true, the second argument is returned. If it’s not true, the third argument is returned.
Return the First Monday of Each Month in SQLite
We can use SQLite’s DATE()
function to return the first Monday of each month for a given year, based on the date we provide.
But it’s not limited to Monday. We can also get the first Tuesday, Wednesday, Thursday, Friday, etc of each month.
Continue readingGet the Last Day of the Month in PostgreSQL
We can use the following technique in PostgreSQL to return the last day of a given month.
This could be the last day of the current month, or the last day of the month based on a date that we specify.
Continue reading