Problems when making an SQL query with the use of UNION

0

I have the following problem when trying to make this query SQL in MySQL

SELECT *  
 FROM Like__post 
 WHERE id__post_ = 2 
UNION 
SELECT * 
 FROM Post 
 WHERE id__post = 2' me genera el siguiente error '
SELECT * 
 FROM Like__post 
 WHERE id__post_ = 2 
UNION 
SELECT *  
 FROM Post 
 WHERE id__post = 2 LIMIT 0, 25
  

MySQL said: Documentation   # 1222 - The used SELECT statements have a different number of columns'

I really do not know why this error is caused

    
asked by Code tutoriales 14.12.2017 в 15:23
source

2 answers

0

The UNION operator is used to combine the result set of two or more SELECT instructions.

And to be able to use it, these three rules must be fulfilled

  • Each SELECT statement within the union must have the same number of columns
  • Columns must also have similar data types
  • The columns of each SELECT statement must also be in the same order
answered by 14.12.2017 в 16:12
-1

The SELECT that make up the UNION must have the same number of columns and same names. Compare the structure of Like__post and post to see if there is not the problem.

    
answered by 14.12.2017 в 15:29