按姓名模糊查询,返回userid, userName,phone,email四个字段table1,table2,table3可能都有匹配的信息,但是table1,table2,table3,中的字段名称可能不是userid,userName,phone,email
例如 table1中的字段为 cusid,cusName,cusPhone,cusemail,当然表中不止四个字段
如何将查询结果一起返回呢?
存储过程怎么写呢

解决方案 »

  1.   

    select userid, userName,phone,email
    from table1 
    where username like '王'
    union all
    select userid, userName,phone,email
    from table2 
    where username like '王'
    union all
    select userid, userName,phone,email
    from table3 
    where username like '王'
      

  2.   

    得把table1,table2,table3对应的字段列出来才能union啊
      

  3.   

    使用union all来连接三个表.但是得确保每个表四个字段的类型要一样,如果不一样,使用cast()进行转换.
    select userid , userName , phone , email from tb1 where ...
    union all
    select cast(col1 as userid的类型), ... from tb2 where ...
    union all
    select cast(col1 as userid的类型), ... from tb3 where ...