3个表table1           |        table2          |          table3
----------------------------------------------------------------------------
type               |        type              |          type
adduser       |        adduser      |         adduser 
addtime       |        addtime       |         addtime  
addip           |
 因为table1 多了一个addip字段 导致与其他表结构不同 无法使用union all联查select type,adduser,addtime,addip  from table1 where adduser='$wd';
select type,adduser,addtime  from table2 where adduser='$wd';
select type,adduser,addtime  from table3 where adduser='$wd';请教怎么将上面3个语句整合成一个语句正常返回结果

解决方案 »

  1.   

    //用字符串
    select type,adduser,addtime,addip  from table1 where adduser='$wd'
    union all
    select type,adduser,addtime,'addip2'  from table2 where adduser='$wd'
    union all
    select type,adduser,addtime,'addip3'  from table3 where adduser='$wd'
      

  2.   

    使用字符串占位就可以了
    select type,adduser,addtime,addip  from table1 where adduser='$wd'
    union all
    select type,adduser,addtime,'xxxx'  from table2 where adduser='$wd'
    union all
    select type,adduser,addtime,'xxxx'  from table3 where adduser='$wd'
      

  3.   

    select type,adduser,addtime,addip  from table1 where adduser='$wd'
    union all
    select type,adduser,addtime,null  from table2 where adduser='$wd'
    union all
    select type,adduser,addtime,null  from table3 where adduser='$wd';
      

  4.   

    select type,adduser,addtime,addip  from table1 where adduser='$wd'
    union all
    select type,adduser,addtime,''  from table2 where adduser='$wd'
    union all
    select type,adduser,addtime,''  from table3 where adduser='$wd';
      

  5.   

    null占位符
    ++