复合主键查询问题
日期:2007-06-10 荐:
复合主键查询问题如何查询复合主键数据不在另外一个表中如果不是复合主键,原来我一般采用:select * from Table1 where id not in(select id from Table2)现在这张表试复合主键,我采用下面这种方式,后来发现是错误select * from Table1 where id1 not in(select id1 from Table2) and id2 not in(select id2 from Table2)各位大侠,帮我解决一下select a.*from table1 ainner join table2 bon a.id<>b.id应该没有错误啊报什么错?没有报错,是结果存在错误to : xluzhong(Ralph)你的语句不对,因为是复合主键,我采用:select a.*from table1 ainner join table2 bon a.id1<>b.id1 and a.id2 <> b.id2结果也是错误,跑出几十万条数据出来了從來沒有用過學習﹗﹗在此只有幫樓主你UPselect * from Table1 where id2 not in(select id1,id2 from Table1 where id1 not in(select id1 from Table2) 终于搞定了,其实很简单select * from Table1 where (id1 not in(select id1 from table2)) or (id2 not in(select id2 from table2 where id1 = Table1.id1))大家帮我看看是否真确
标签: