MySQL has an IFNULL() function that allows us to easily replace NULL values with another value.
MySQL
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.
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.
MySQL NULLIF() Explained
In MySQL, NULLIF() is a flow control function that returns NULL if both of its arguments are equivalent. Otherwise it returns the first argument.
How to Get the Number of Days in a Month in MySQL
Check out the following technique in MySQL if you need to find out how many days are in a month based on a given date.
MySQL COALESCE() Explained
In MySQL, the COALESCE() operator returns the first non-NULL value in the list, or NULL if there are no non-NULL values.
Delete Duplicate Rows in MySQL (Ignores Primary Key)
The following example deletes duplicate rows in MySQL while ignoring the primary key or unique identifier column.
The example deletes duplicate rows but keeps one. So in the case of two identical rows, it deletes one of them and keeps the other.
How to Get the Last Day of the Month in MySQL
We can use MySQL’s LAST_DAY() function 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.
2 Ways to Return Rows that Contain Only Non-Alphanumeric Characters in MySQL
Below are two options for finding those rows that only contain non-alphanumeric characters in MySQL.
Non-alphanumeric characters include punctuation characters like !@#&()–[{}]:;',?/* and symbols like `~$^+=<>“, as well as whitespace characters like the space or tab characters.
Fix “ERROR 3942 (HY000): Each row of a VALUES clause must have at least one column” when using the VALUES Statement in MySQL
If you’re getting an error that reads “ERROR 3942 (HY000): Each row of a VALUES clause must have at least one column” in MySQL, you could have an empty row constructor when using the VALUES statement.
To fix this issue, make sure you’ve got at least one value in each ROW() clause within the VALUES statement.