>select * from a,b where a.id = b.id(+) and b.id is null</P>
>上边的好像是oracle的,我在SQL里边是这样写的</P>
>select a.id ,b.* from a left join b on a.id=b.id where b.id is null</P>
>应该跟上边的是差不多的意思</P>
>我本来的意思是这样的写<BR>select * from a where aa.id not in (select id from b)<BR>或者: <BR>select id from a minus select id from b</P>) J$ z7 ^0 a6 q; l( Y1 g8 B
>可是今天查阅了一下资料,说这样写的效率比较低,有人推荐了一种写法据说效率很高,但不知道在什么数据库上可用,我还没有测试过!<BR>select * from a,b where a.id = b.id(+) and b.id is null</P>1 ?& B* F6 {7 ]. H
>希望有人测试后给个结果! <BR></P>
><br>我建了两个数据表,a和b, a 表中有id字段,b表中有id字段,查询语句是这样写的:<br>SELECT id<br>FROM a<br>WHERE id not in ( SELECT id FROM b)</P>
>但测试的时候出现如下错误:1064 You have an error in your SQL syntax near 'SELECT id FROM b)'at line 1</P>
>另外我用select * from a,b where a.id = b.id(+) and b.id is null这种方法时也出现跟上面类似的错误,把(+)去掉后显示无数据,如果正确应该有数据的。</P>
>这是什么原因?难道跟PHP(4)和MYSQL(3.23.56)版本有关?请高手给予指点。</P>0 t9 p7 `1 l* e) i' @
>MYSQL数据库我没有使用过!主要看它是不是支持select语句的嵌套使用!</P>
>你有没有试过select id from a minus select id from b的使用?</P>( o' v" X: N- B% C) H0 A( A
>这里面主要是minus函数的使用,不知道MYSQL中是不是有这个函数,或者有同样功能的函数也可以使用在这里,你可以查看一下帮助!</P>
>不太清楚 </P>
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) | Powered by Discuz! X2.5 |