JavaEar 专注于收集分享传播有价值的技术资料

Union 'expression must have same datatype as corresponding expression'

I'm trying to do a union select, 4 of the columns in my first query is a number, I don't need this 4 numbers in my second query so I just want to display a '0' or null for those columns in the second query.

My query is something like this

Select Column A, Column B, Number A, Number B, Number C, Number D
   From Table A
UNION
Select Column A, Column B
   From Table B

2个回答

    最佳答案
  1. Just fill the values.

    Select Column A, Column B, Number A, Number B, Number C, Number D
       From Table A
    UNION
    Select Column A, Column B, NULL, NULL, NULL, NULL
       From Table B
    
  2. 参考答案2
  3. Then you can just do

    Select Column A, Column B, Number A, Number B, Number C, Number D
    From Table A
    UNION
    Select Column A, Column B, 0, 0, 0, 0
    From Table B