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

Fix “ERROR: each INTERSECT query must have the same number of columns” in PostgreSQL

When using PostgreSQL’s INTERSECT operator, if you encounter an error that reads “ERROR: each INTERSECT query must have the same number of columns“, it’s because there’s a mismatch in the number of columns returned by the queries on either side of the INTERSECT operator.

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

Continue reading

Fix “ERROR 1054 (42S22): Unknown column ‘…’ in ‘on clause'” in MariaDB

If you’re getting an error that reads something like “ERROR 1054 (42S22): Unknown column ‘tab.ColName’ in ‘on clause”” in MariaDB, here are three likely causes:

  • The column doesn’t exist.
  • You’re trying to reference an aliased column by its column name.
  • Or it could be the other way around. You could be referencing the column with an alias that was never declared.
Continue reading

Fix “ERROR:  each EXCEPT query must have the same number of columns” in PostgreSQL

When using PostgreSQL’s EXCEPT operator, if you encounter an error that reads “ERROR:  each EXCEPT query must have the same number of columns“, it’s because there’s a mismatch in the number of columns returned by the queries on either side of the EXCEPT operator.

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

Continue reading

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

Fix “ERROR 1136 (21S01): Column count doesn’t match value count at row 1” when Inserting Data in MySQL

One of the more common error message in MySQL goes like this: “ERROR 1136 (21S01): Column count doesn’t match value count at row 1“.

This error typically occurs when you’re trying to insert data into a table, but the number of columns that you’re trying to insert don’t match the number of columns in the table.

In other words, you’re either trying to insert too many columns, or not enough columns.

Continue reading