不建视图
选出table1中id为1 或 table2中id为1 table3中id为1 或 table3中id为1 的所有记录

解决方案 »

  1.   

    select * from table1 where id=1
      

  2.   

    效率高:select * from table1 where id=1
    union all
    select * from table2 where id=1
    union all
    select * from table3 where id=1
      

  3.   

    视图好
    create view  test_view
    as 
    select * from table1 where id=1
    union all
    select * from table2 where id=1
    union all
    select * from table3 where id=1执行!
    select  *  from  test_view
      

  4.   

    除非各个表字段都相同,否则不能用Union
      

  5.   

    to sxdoujg() 
    -------------------------
    select * from table1 where id=1
    union all
    select * from table2 where id=1
    union all
    select * from table3 where id=1
    -------------------------
    不对呀,报错服务器: 消息 205,级别 16,状态 1,行 1
    包含 UNION 运算符的 SQL 语句中的所有查询都必须在目标列表中具有相同数目的表达式。
      

  6.   

    各个表,各个字段都不同,都没任何关系,我想在asp里做一个联合查询,搜索出表1中字段为xx或表2中字段为xx或表3中字段为xx的记录,请问应该怎么写这个sql呢
      

  7.   

    table3中id为1 或 table3中id为1
    是不是写错了,两个都是table3
      

  8.   

    哦,写错了
    不建视图
    选出table1中id为1 或 table2中id为1 table3中id为1 或 table4中id为1 的所有记录我各个表里字段数不一