MySQL ERROR 1222 (21000): The used SELECT statements have a different number of columns

The SELECTs combined with UNION return different numbers of columns.

Seen on: SQL

Meaning

Each SELECT in a UNION must return the same number of columns with compatible types, in the same order.

Common causes

  • Different column counts in UNION parts
  • SELECT * on tables with different columns

⚡ Quick fix

  1. List columns explicitly in each SELECT
  2. Pad with NULL AS col where a part lacks a column

Detailed fix by platform

SQL

  1. SELECT id, email, NULL AS phone FROM users UNION ALL SELECT id, email, phone FROM leads;

How to diagnose

  1. Counts — Columns per SELECT?
  2. Recent change — Did it start after a deploy, upgrade, or configuration change? Compare with the last working version.

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.