'2018/08/18'에 해당되는 글 1건

728x90

두개의 테이블에서 불일치하는 데이터를 찾는 SQL 명령으로 idx 는 index를 타는 칼럼이다.

select * from favoriteBook where staffidx not in (select idx from member);

select * from FavoriteBook where staffidx not in (select idx from SYS_MEMBER);

 

불일치 데이터를 찾아서 지우는 SQL 문

delete from FavoriteBook where staffidx not in (select idx from member);

delete from FavoriteBook where staffidx not in (select idx from SYS_MEMBER);

 

select * from FavoriteBook where myidx not in (select idx from SYS_MEMBER);
delete from FavoriteBook where myidx not in (select idx from SYS_MEMBER);

 

누락된 데이터 찾기

SELECT b.fieldB, a.fieldA FROM tableA a RIGHT OUTER JOIN tableB b ON a.fieldA = b.fieldB WHERE a.fieldA IS NULL;

 

불일치 데이터 찾기

두 테이블의 uid는 서로 같고 특정 필드 업데이트에 따른 불일치가 되는 데이터 찾기

즉 백업 이후에 변경된 데이터 찾기 같은 셈이다.

select a.uid,a.direct,b.direct,a.is_checking,b.is_checking from data_0218 a, data_0220 b where a.uid=b.uid and a.is_direct=5 and a.is_checking=0 and b.is_checking NOT IN(0);

 

 

 

 

 

'SQL' 카테고리의 다른 글

테이블명 변경  (0) 2019.03.11
MySQL 사용자 권한 부여  (0) 2018.11.26
Toad for MySQL - Database Diagram  (0) 2017.06.02
[강좌] 한방에 개념잡는 SQL 조인  (0) 2017.02.26
[MySQL] 정규식을 활용한 검색 (REGEXP)  (0) 2016.12.11
블로그 이미지

Link2Me

,