A 表 B表它们有共同字段 code用户输入:"10001";两表无任何关联关系``需要1条SQL找出2表中所有字段条件:
A表中code=10001 但B表中code无10001或B表中code=10001 但A表中code无10001我写的是select * from A as a ,B as b where a.code=b.code and a.code='10001';这样写必须2表code都必须相等``如果A表中code有等于10001的而B表中code无10001那么查找结果就为空 了`那位大哥帮帮我`

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【xiaomaha】截止到2008-07-15 09:03:52的历史汇总数据(不包括此帖):
    发帖的总数量:59                       发帖的总分数:2274                     每贴平均分数:38                       
    回帖的总数量:144                      得分贴总数量:38                       回帖的得分率:26%                      
    结贴的总数量:49                       结贴的总分数:2174                     
    无满意结贴数:7                        无满意结贴分:550                      
    未结的帖子数:10                       未结的总分数:100                      
    结贴的百分比:83.05 %               结分的百分比:95.60 %                  
    无满意结贴率:14.29 %               无满意结分率:25.30 %                  
    楼主加油
      

  2.   

    没太看懂你的意思select * from A as a ,B as b where a.code=b.code union all select * from a where a.code='10001';
      

  3.   

    本帖最后由 kokobox 于 2008-07-15 12:10:37 编辑
      

  4.   

    哈哈 KOKO 大哥写错别字啦俺还是不明白楼主什么意思.既然两表没有任何关联.A表中有 A表中code=10001 但B表中code无10001 
    也就是B表中没有code=10001 的数据.
    那你还取B表中的数据做什么? 即使取出来也和code=10001 没有关系呀!
      

  5.   

    用join   on 不行吗
      

  6.   

    select t.* from A t where t.code<>'10001'unionselect tt.* from B tt were tt.code = '10001'
    但需要注意,t.* 与tt.*查询的记录数必需一致(包括数据类型)
      

  7.   


    select * from A t where t.code='10001'unionselect * from B t1 were t1.code = '10001'
    楼主意思是有可能是A中的code='10001'或B中的code='10001',但不知道具体是A还是B,需要把符合code='10001'的数据都查询出来吧。
      

  8.   

    Hql怎么写啊```我写成from TabScan a full join TabBill b on a.billCode=b.billCode where a.billCode=? order by a.scanDate
    就出
    org.hibernate.hql.ast.QuerySyntaxError
    为什么语法错误?
    在SQL里面没问题啊
      

  9.   


    select * from A t where t.code='10001' and not exists (select 1 from B b where b.code='1001')unionselect * from B t1 were t1.code = '10001' and not exists(select 1 from A a where a.code='1001')使用这个,效率还不错哦,呵呵,比<>或者!=效率高很多倍
      

  10.   


    select * from A join B on 
    (
    (A.code='10001' and A.code<>B.code) 
    or
    (B.code='10001' and A.code<>B.code)
    )
      

  11.   

    union 
    对两个不关联的表做处理
      

  12.   


    select * from A join B on
    (
    (A.code=10001 and B.code<>10001)
    or
    (B.code=10001 and A.code<>10001)
    )
    混乱。。
      

  13.   

    学习一下union,不太懂楼主的意思。
      

  14.   

    SELECT * FROM A, B WHERE (A.code='10001' AND B.code<>'10001') OR (A.code<>'10001' AND B.code='10001');
      

  15.   

    select A.a,B.b from A ,B  where( b.code='10001' or a.code='10001');
      

  16.   

    select * from A  Uniom Select * from b