Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The used SELECT statements have a different number of columns

Tags:

sql

mysql

union

For examples I don't know how many rows in each table are and I try to do like this:

SELECT * FROM members 
UNION 
SELECT * FROM inventory

What can I put to the second SELECT instead of * to remove this error without adding NULL's?

like image 875
good_evening Avatar asked Sep 01 '10 20:09

good_evening


1 Answers

Put the columns names explicitly rather than *, and make sure the number of columns and data types match for the same column in each select.

Update:

I really don't think you want to be UNIONing those tables, based on the tables names. They don't seem to contain related data. If you post your schema and describe what you are trying to achieve it is likely we can provide better help.

like image 133
D'Arcy Rittich Avatar answered Sep 17 '22 11:09

D'Arcy Rittich