求一条SQL语句`谢谢`
时间:2008-07-18 10:10:50
来源:论坛整理 作者: 编辑:chinaitzhe
它们有共同字段 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那么查找结果就为空 了`
那位大哥帮帮我`
网友回复:此回复为自动发出,仅用于显示而已,并无任何其他非凡作用
楼主【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 %
楼主加油网友回复:没太看懂你的意思
select * from A as a ,B as b where a.code=b.code union all select * from a where a.code='10001';
网友回复:
- SQL code
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ select * from A t where t.code='10001' union select * from B tt where tt.code <> '10001'
网友回复:
哈哈 KOKO 大哥写错别字啦
俺还是不明白楼主什么意思.既然两表没有任何关联.A表中有 A表中code=10001 但B表中code无10001
也就是B表中没有code=10001 的数据.
那你还取B表中的数据做什么? 即使取出来也和code=10001 没有关系呀!
网友回复:用join on 不行吗
网友回复:不明白你到底想查什么,晕了。
两个表既然没有关联你联起来干什么呢?
网友回复:楼上说的有意思
网友回复:学习
网友回复:
网友回复:union 处理即可
网友回复:select t.* from A t where t.code <>'10001'
union
select tt.* from B tt were tt.code = '10001'
但需要注重,t.* 与tt.*查询的记录数必需一致(包括数据类型)
网友回复:
- SQL code
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ select * from A t where t.code='10001' union select * from B t1 were t1.code = '10001'
楼主意思是有可能是A中的code='10001'或B中的code='10001',但不知道具体是A还是B,需要把符合code='10001'的数据都查询出来吧。
网友回复: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里面没问题啊
网友回复:
- SQL code
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ select * from A t where t.code='10001' and not exists (select 1 from B b where b.code='1001') union select * from B t1 were t1.code = '10001' and not exists(select 1 from A a where a.code='1001')
使用这个,效率还不错哦,呵呵,比 <>或者!=效率高很多倍
网友回复:
- SQL code
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ select * from A join B on ( (A.code='10001' and A.code<>B.code) or (B.code='10001' and A.code<>B.code) )
网友回复:union
对两个不关联的表做处理
网友回复:学习
网友回复:
- SQL code
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ select * from A join B on ( (A.code=10001 and B.code<>10001) or (B.code=10001 and A.code<>10001) )
混乱。。
网友回复:学习一下union,不太懂楼主的意思。
网友回复:
改过来了,呵呵
网友回复:
- SQL code
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ SELECT * FROM A, B WHERE (A.code='10001' AND B.code<>'10001') OR (A.code<>'10001' AND B.code='10001');
网友回复:select A.a,B.b from A ,B where( b.code='10001' or a.code='10001');
网友回复:
网友回复:select * from A Uniom Select * from b
关键字:一条,SQL,语句,谢谢,
下一篇:下面没有链接了











文章评论
共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面