Update from & Left Join

UPDATE TFSTERMCFG 
SET TMS_SOFTWARE_SCHD_NEW_CFG = SOFTWARE_GROUP
FROM TFSTERMCFG t1
LEFT JOIN MATERMCFG t2

ON t1.ACQ_ID=t2.ACQ_ID AND t1.MERCHANT_ID= t2.MERCHANT_ID AND t1.TERMINAL_ID=t2.TERMINAL_ID



****LEFT JOIN Example :


create table tableA
(
    COL1 VARCHAR(255)  null,
    COL2 VARCHAR(255)  null,
    COL3 VARCHAR (255)  null
)


insert into tableA values ('1','11','111');
insert into tableA values ('2','22','222');
insert into tableA values ('3','33','333'); 


create table tableB
(
    COL1 VARCHAR(255)  null,
    COL4 VARCHAR(255)  null
)


insert into tableB values ('1','X');
insert into tableB values ('2','Y');
insert into tableB values ('2', null)


select * from tableA;
select * from tableB;

1. Result for 

select * from tableA a
left join tableB b
on A.col1=b.col1 

COL1 COL2 COL3 COL1 COL4
1 11 111 1 X
2 22 222 2 Y
2 22 222 2 NULL
3 33 333 NULL NULL

2.Result for
select * from tableA a
left join tableB b
on A.col1=b.col1
where b.col1 is null

COL1 COL2 COL3 COL1 COL4
3 33 333 NULL NULL

你可能感兴趣的:(数据库和Oracle)