This topic has been archived. It cannot be replied.
-
工作学习 / 专业技术讨论 / 请教各位SQL问题:有两个表,里面都有一个相同的field,能用一个SQL语句找出这个Field在这两个表中所有的不同值吗?谢谢。
-vinatca(LD is back);
2006-6-20
(#3037443@0)
-
UNION
-hahahaly(hahahaly);
2006-6-20
(#3037482@0)
-
way to go
-iwantcar(流浪的EnjoyStudying);
2006-6-20
(#3037663@0)
-
LEFT JOIN
-canadiantire(轮胎-cui bono?);
2006-6-20
(#3037646@0)
-
how? I don't think so.
-iwantcar(流浪的EnjoyStudying);
2006-6-20
(#3037662@0)
-
select field2 from ( select t1.field1, t2.field1 as field2 from t1 left join t2 on t1.field1=t2.field1 ) t3 where t3.field2 is null // and then switch t1,t2 and union all
-canadiantire(轮胎-cui bono?);
2006-6-20
(#3037690@0)
-
you are right. how about this:(select field from table1 where not exist(select * from table2 wehre table2.field = table1.field)) union all (select field from table2 where not exist(select * from table1 wehre table1.field = table2.field)) ;
-iwantcar(流浪的EnjoyStudying);
2006-6-20
{210}
(#3037729@0)
-
or you can use FULL OUTER JOIN if you are using Oracle 9i/10g, then check null for either column
-zdq(zdq);
2006-6-20
(#3037763@0)
-
MINUS each other, then UNION all
-zdq(zdq);
2006-6-20
(#3037698@0)
-
Select * from table1 where field not in (select field from table2)
Union all
Select * from table2 where field not in (select field from table1)
-hard20(hard20);
2006-6-20
(#3038073@0)