how to write this SQL SELECT command?(100分)

  • 主题发起人 主题发起人 朝朝
  • 开始时间 开始时间

朝朝

Unregistered / Unconfirmed
GUEST, unregistred user!
2 tables same struc.
verify them. some like file compare,
select deferents records.
example:table1
record field1 field2 field3 ... fieldN
1 600000 N 1000 ... A374412141
record field1 field2 field3 ... fieldN
2 600688 N 1000 ... A374412141
record field1 field2 field3 ... fieldN
3 600000 N 1000 ... A374412141
 
select * from table1 where field1='?',fieldn='?';
 
2 tables same struc.
verify them. some like file compare,
select record from table1 if it not found in table2 or deferent to table2.
example:table1
record field1 field2 field3 ... fieldN
1 600000 0 1000 ...
record field1 field2 field3 ... fieldN
2 600000 N 1000 ... Z
record field1 field2 field3 ... fieldN
3 600688 N 1000 ... P
table2
record field1 field2 field3 ... fieldN
1 600000 0 2000 ...
record field1 field2 field3 ... fieldN
2 600000 N 1000 ... Z
record field1 field2 field3 ... fieldN
3 600688 N 1000 ... Z

result:
record field1 field2 field3 ... fieldN
1 600000 0 1000 ...
record field1 field2 field3 ... fieldN
2 600688 N 1000 ... P

if i get a acceptable answer in 3 days,u get 300;in 6 days,150;12 days,75.
>12days,50.today is 2000-09-15,Fri.
help! thank u.
 
select * from table1
minus
select * from table2;
得到不在table2中的tabl1的所有记录。
 
zs,在什么环境下得到正确结果?
 
在ORACLE中肯定可以,在别的大型数据库(如SQL SERVER、INFORMIX、SYBASE,DB2等)
中应该也可以,不过不一定是用MINUS,可能有别的关键字。
select * from table1
minus
select * from table2;
得到不在table2中的tabl1的所有记录。
反过来
select * from table2
minus
select * from table1;
得到不在table1中的tabl2的所有记录。
 
select * from table1 <strong>left outer join</strong> table2
on table1.field1=table2.field1 and table1.field2=table2.field2 and
table1.field3=table2.field3 and table1.field4=table2.field4
将返回table1中所有不符合ON指定的条件的记录,改成<strong>right outer join</strong>
将返回table2中所有不符合ON指定的条件的记录!
select * from table1,table2将返回完全相同的所有记录!
 
在oracle下zs或yck的方法,但其他數據庫只能用下面的語句:
select * from table1 where table1.primaryKey not in (select table1.primaryKey from table1 t1,table1 t2 where t1.field1=t2.field1 and t1.field2=t2.field2 and
t2.field3=t2.field3 and t1.field4=t2.field4)
 
haha. thank u.给分乐.
 
接受答案了.
 
后退
顶部