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.

Continue reading

3 Ways to Delete Duplicate Rows in SQL Server while Ignoring the Primary Key

The following examples use T-SQL to delete duplicate rows in SQL Server while ignoring the primary key or unique identifier column.

More specifically, the examples delete duplicate rows but keep one. So, given two identical rows, one is deleted and the other remains. This is often referred to as “de-duping” the table, “deduplication” of the table, etc.

Continue reading

Fix “ERROR 1222 (21000): The used SELECT statements have a different number of columns” when using UNION in MariaDB

When using the UNION operator in MariaDB, you may encounter the following error: “ERROR 1222 (21000): The used SELECT statements have a different number of columns”.

This error occurs when the number of columns returned by each SELECT statement is different.

The way to fix this is to ensure that both SELECT statements return the same number of columns.

Continue reading

Fix “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.

Continue reading