📄 subject_25288.htm
字号:
<p>
序号:25288 发表者:rafael 发表日期:2002-12-20 12:00:04
<br>主题:非常奇怪的select 问题!! 有数据库经验的朋友来帮看下呀!
<br>内容:SELECT tabl1.name, table1.age, table1.micro FROM tabl2 RIGHT OUTER JOIN table1 ON table1.name=table2.name WHERE tale1.name <> table2.name AND table1.age <> table2.age AND table1.micro <> table2.micro<BR><BR>我要的是在table1中有,且name,age,micro在table2 中都没有相同的记录,上面的这个select 语句很奇怪,得到的结果不全,只能得到部分结果.<BR>我的意思就是假如<BR>表1 表2<BR>name age micro name age micro<BR>aaa 30 test aaa 30 test<BR>bbb 20 good bbb 20 good<BR>ccc 22 okok ccc 21 okok<BR>ddd 20 nice eee 35 OOOOO<BR><BR>那我要的结果就是选出<BR>ccc 22 okok<BR>ddd 20 nice <BR>这两条记录来<BR><BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:凯凯 回复日期:2002-12-20 12:04:31
<br>内容:SELECT tabl1.name, table1.age, table1.micro FROM tabl2 RIGHT OUTER JOIN table1 ON table1.name=table2.name WHERE table1.age <> table2.age AND table1.micro <> table2.micro
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:rafael 回复日期:2002-12-20 13:11:36
<br>内容:你的方法不行呀,结果漏掉了一些符合条件的呀
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:凯凯 回复日期:2002-12-20 13:34:03
<br>内容:漏掉是因为用了RIGHT OUTER JOIN table1 ON table1.name=table2.name ,所以象ddd就肯定会漏掉。<BR>要不你分两次,第二次按name找出tabl1中有但tabl2中没有的记录。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:凯凯 回复日期:2002-12-20 13:34:58
<br>内容:你可能做一个存储过程,分两次找,将找到的记录全部放到一个临时表中,一次返回一个结果集。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:rafael 回复日期:2002-12-20 14:16:06
<br>内容:哦,我试试
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:coni 回复日期:2002-12-20 18:53:44
<br>内容:SELECT t21.name, t21.age, t21.micro<BR>FROM t21<BR>WHERE t21.name not in(select t22.name from t22 where t21.age = t22.age AND t21.micro = t22.micro) and<BR> t21.age not in(select t22.name from t22 where t21.name = t22.name AND t21.micro = t22.micro) and<BR> t21.name not in(select t22.name from t22 where t21.age = t22.age AND t21.name = t22.name)
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:coni 回复日期:2002-12-20 19:07:48
<br>内容:SELECT t21.name, t21.age, t21.micro<BR>FROM t21<BR>WHERE t21.name not in(select t22.name from t22 where t21.age = t22.age AND t21.micro = t22.micro) and<BR> t21.age not in(select t22.age from t22 where t21.name = t22.name AND t21.micro = t22.micro) and<BR> t21.micro not in(select t22.micro from t22 where t21.age = t22.age AND t21.name = t22.name) <BR><BR>I 刚才打错了!这样运行的速度可能比较慢!如果数据不多效果应该还不错!<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:rafael 回复日期:2002-12-20 21:47:01
<br>内容:数据很多呀,没个表10万条记录,慢了点
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:coni 回复日期:2002-12-21 10:14:26
<br>内容:SELECT t21.name, t21.age, t21.micro<BR>FROM t21 left join t22 on t21.name=t22.name<BR>where t21.age<>t22.age or t22.age is null or t21.micro<>t22.micro or t22.micro is null<BR><BR>I 发现问题是有NULL值产生的。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:骆驼之沙漠王子 回复日期:2002-12-21 17:20:54
<br>内容:试试这个:<BR>SELECT table1.name, table1.age, table1.micro<BR>FROM table1<BR>WHERE NOT EXISTS<BR> (SELECT table2.name, table2.age, table2.micro<BR> FROM table2<BR> WHERE table1.name = table2.name AND table1.age = table2.age AND <BR> table1.micro = table2.micro)
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -