wjmmml(笑着悲伤) :
不好意思,是这样的,第一,数据库不是我设计的,
第二,数据量很大,一张表有可能上几十万条,所以分开.这不是我决定的事,请帮忙

解决方案 »

  1.   

    此方法好笨.
    不要建临时视图呀。
    如果多线程就出错呀。
    建议直接得到如下SQL
    select * from table1
    union
    select * from table2
    union 
    select * from table3
      

  2.   

    sql语句print出来,sql语句是不是拼的不对
      

  3.   

    建议,不要创建视图,
    把你的SQL语句全部打出来看看。然后在数据库中去查询,看看结果。
    贴出来!
      

  4.   

    再问一下,我怎么感觉加上UNION后就自动加上了distinct 了呢??   是不是这样啊????????????????????????????
      

  5.   

    就好像是这样了(我感觉,不知道对不对)
    select * from table1 union select distinct * from table2
     ==    
    select distinct * from table1
    select distinct * from table2  两表的记录加在一起我的意思是,用了UNION后,就好象有这样的结果,不知道对不对,请告诉我!!!1
      

  6.   

    不对的.
    给你看看我的SQL,连接的时候,要分别处理的.你要自己筛掉.如果不行,把你的表结构贴出来.我再帮你看看.最好把你的实际的SQL语句贴出来.
    sql="select a.*,b.agent_name,c.Name as group_name from DIR_NUM_RES a,dir_agent_info b,DIR_SECU_GROUP c "+
    "WHERE (a.agent_id = b.agent_id and a.agent_id is not null) "+
    "and (a.group_id=c.group_id and a.group_id is not null) and a.NUM_NO like '%" + FromNum + "%' "+
    " union "+
    "select a.*,'未分配' as agent_name,c.Name as group_name "+
    "from DIR_NUM_RES a,DIR_SECU_GROUP c "+
    "where a.agent_id is null "+
    "and a.group_id is not null "+
    "and a.group_id=c.group_id and a.NUM_NO like '%" + FromNum + "%' "+
    "union "+
    "select a.*,'未分配' as agent_name,'未分配' as group_name from DIR_NUM_RES a "+
    "where a.agent_id is null and a.group_id is null and a.NUM_NO like '%" + FromNum + "%' ";
      

  7.   

    union 改成union all 就可以了