#1222 - The used SELECT statements have a different number of columns

后端 未结 5 881
Happy的楠姐
Happy的楠姐 2021-02-13 19:55

Why am i getting a #1222 - The used SELECT statements have a different number of columns ? i am trying to load wall posts from this users friends and his self.

S         


        
5条回答
  •  眼角桃花
    2021-02-13 20:28

    You are using MySQL Union.

    UNION is used to combine the result from multiple SELECT statements into a single result set.
    
    The column names from the first SELECT statement are used as the column names for the results returned. Selected columns listed in corresponding positions of each SELECT statement should have the same data type. (For example, the first column selected by the first statement should have the same type as the first column selected by the other statements.)
    

    Reference: MySQL Union

    Your first select statement has 4 columns and second statement has 6 as you said wall_post has 6 column. You should have same number of column and also in same order in both statement. otherwise it shows error or wrong data.

提交回复
热议问题