比较两个表的最快方法是什么? (DBMR3010)

~ 0 min
2020-10-13 17:46

“EXCEPT”运算符用于合并两个“SELECT”语句,并从第一个SELECT语句返回第二个SELECT语句未返回的列。 DBMaker不支持EXCEPT运算符。 因此,我们提供了一种替代解决方法。 但是,该命令仅比较两栏,而不能比较BLOB数据。  

 

该命令代替“表格t1,表格t2除外”(“table t1 except table t2”)。

 select * from t1 where not exists(select 0 from t2 where t1.c1 = t2.c1 and (t1.c2 = t2.c2 or (t1.c2 is null and t2.c2 is null)));  

 

该命令代替“表格t2,表格t1除外”(“table t2 except table t1”)

select * from t2 where not exists(select 0 from t1 where t1.c1 = t2.c1 and(t1.c2 = t2.c2 or (t1.c2 is null and t2.c2 is null)));  

 

例如,有两个表格,t1和t2。

Table t1  


C1              C2
======= =======
              1              1  
              2              2   
              3              3  

Table t2  


C1              C2
======= =======   
              1              1  
              2              2     
              4              4

 

执行第一个命令替换“ t1除了t2”(“t1 except t2”)。 您可以在t1中获得3,但不在t2中。

dmSQL> select * from t1 where not exists(select 0 from t2 where t1.c1 = t2.c1 and (t1.c2 = t2.c2 or (t1.c2 is null and t2.c2 is null)));  
 
C1              C2
======= =======
              3              3  

 

执行第二个命令替换“除了t1之外的t2”(“t2 except t1”)。您可以在t2中获得4,但不在t1中”  

dmSQL> select * from t2 where not exists(select 0 from t1 where t1.c1 = t2.c1 and(t1.c2 = t2.c2 or (t1.c2 is null and t2.c2 is null)));
 
C1              C2 
======= =======
              4              4  
 

Version: DBMaker 5.4.2
Product: Normal/Bundle
Platform: Windows/Linux

平均分: 0 (0 投票)

你不能对该内容发表评论

标签