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那么查找结果就为空 了`那位大哥帮帮我`
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那么查找结果就为空 了`那位大哥帮帮我`
楼主【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 %
楼主加油
也就是B表中没有code=10001 的数据.
那你还取B表中的数据做什么? 即使取出来也和code=10001 没有关系呀!
但需要注意,t.* 与tt.*查询的记录数必需一致(包括数据类型)
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'的数据都查询出来吧。
就出
org.hibernate.hql.ast.QuerySyntaxError
为什么语法错误?
在SQL里面没问题啊
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')使用这个,效率还不错哦,呵呵,比<>或者!=效率高很多倍
select * from A join B on
(
(A.code='10001' and A.code<>B.code)
or
(B.code='10001' and A.code<>B.code)
)
对两个不关联的表做处理
select * from A join B on
(
(A.code=10001 and B.code<>10001)
or
(B.code=10001 and A.code<>10001)
)
混乱。。