Hi Friends,
I was working with website with millions of records where I need to use UNION SQL Query. I used the UNION SQL query and try to execute it but it shows me below error message.
The used SELECT statements have a different number of columns.
UNION SQL Query
$sql = "(SELECT id, name FROM user) UNION (SELECT * FROM user_reg) ORDER BY id DESC";
Reason why it give me error “The used SELECT statements have a different number of columns.” is, columns does not match in result of both query. If you see first query, i try to get id and name column. In second query, i try to get all columns. So it throws this error.
If you want to use UNION SQL Query, you should match the column of both tables. I hope this helps you.