mysql

How to fix MySQL error "The used SELECT statements have a different number of columns"


The page below show this:

The used SELECT statements have a different number of columns

What is happening, and if possible, how can I fix it?

SELECT * FROM login
INNER JOIN perguntador ON perguntador.autor_id = login.id
UNION ALL
SELECT * FROM perguntador
INNER JOIN perguntadorrespostas
ON perguntadorrespostas.question_id = perguntador.question_id

This code it comes to the tables: login (users), questions (join the login table to access the user_id) and Comments (join the log table for the user name who commented, and join table questions to know which question the user posted your comment).


Solution

  • You are trying to make a UNION between two tables that have different number of columns. Might need to make them uniform. Or add dummy selects to the table missing columns.