In MySQL, the COALESCE()
operator returns the first non-NULL value in the list, or NULL if there are no non-NULL values.
Category: MySQL
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.
Continue readingHow 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.
Continue reading2 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.
Return Only Numeric Values in MySQL
The following MySQL query returns only those rows that have numeric values in a given column.
Continue readingFix “ERROR 1136 (21S01): Column count doesn’t match value count at row 2” when using the VALUES Statement in MySQL
If you’re getting an error that reads something like “ERROR 1136 (21S01): Column count doesn’t match value count at row 2” when using the VALUES
statement in MySQL, it’s probably because there’s a mismatch in the number of columns specified in the ROW()
clauses.
To fix this error, be sure that all ROW()
clauses contain exactly the same number of columns.
Fix “ERROR 1222 (21000): The used SELECT statements have a different number of columns” when using UNION in MySQL
If you’re getting “ERROR 1222 (21000): The used SELECT statements have a different number of columns” when using the UNION
clause in a MySQL query, it’s probably because the number of columns returned by each SELECT
statement is different.
3 Ways to Find Rows that Contain Uppercase Letters in MySQL
Here are three options for returning rows that contain uppercase characters in MySQL.
Continue readingFix “ERROR 1250 (42000): Table ‘…’ from one of the SELECTs cannot be used in global ORDER clause” when using UNION in MySQL
If you’re getting an error that reads “ERROR 1250 (42000): Table ‘…’ from one of the SELECTs cannot be used in global ORDER clause” when using the UNION
clause in a MySQL query, it’s probably because you’re qualifying a column name with its table name.
This doesn’t work in MySQL.
To fix this issue, either remove the table name or use a column alias.
Continue reading