Delete from join 用法
阿新 • • 發佈:2017-10-17
16px div -s span style left join pre 用法 not
delete (別名) from tblA (別名) left join tblb (別名) on。。。用法
1、創建使用的表及數據
CREATE TABLE YSHA ( code VARCHAR(10), NAME VARCHAR(20) ) CREATE TABLE YSHB ( code VARCHAR(10), col VARCHAR(10) ) INSERT INTO YSHA VALUES (1,‘A1‘) INSERT INTO YSHA VALUES (2,‘A2‘) INSERT INTO YSHB VALUES(1,‘Row1‘) INSERT INTO YSHB VALUES(1,‘Row2‘) INSERT INTO YSHB VALUES(1,‘Row3‘) INSERT INTO YSHB VALUES(3,‘Row1‘)
2、delete from left join
DELETE A FROM YSHA A LEFT JOIN YSHB B ON A.code=b.code WHERE b.code is NULL SELECT * FROM YSHA SELECT * FROM YSHB
DELETE FROM YSHA WHERE NOT EXISTS(SELECT 1 FROM YSHB B WHERE YSHA.code=b.code ) SELECT * FROM YSHA SELECT * FROM YSHB
Delete from join 用法