Database/SQL Server
SQL Server - Intersect 연산자(operator)
청렴결백한 만능 재주꾼
2020. 12. 11. 06:46
반응형
Intersect 연산자는 왼쪽 쿼리와 오른쪽 쿼리의 공통된 레코드를 검색한다.(교집합)
Intersect operator retrieves the common records from both the left and the right query of the Intersect operator.
- SQL Server 2005에 소개됨.
Introduced in SQL Server 2005
- 양쪽 두 쿼리에서 열의 개수와 순서가 같아야 한다.
The number and the order of the columns must be same in both the queries
- 데이터 타입은 같거나 반드시 호환이 가능해야 한다.
The data types must be same or at least compatible
Intersect 와 INNER JOIN 의 차이 Difference between Intersect operator and INNER JOIN.
INNER JOIN은 NULL값들을 다르게 취급한다. 그래서 양 쪽에 모두 NULL 값이 있어도 같은 값으로 보지 않기 때문에 리턴하지 않는다. INTERSECT는 NULL값을 동일한 값으로 취급하기 때문에 일치하는 행을 포함시켜 리턴한다.
INNER JOIN treats two NULLS as two different values. So if you are joining two tables based on a nullable column and if both tables have NULLs in that joining column then, INNER JOIN will not include those rows in the result-set, where as INTERSECT treats two NULLs as a same value and it returns all matching rows.
반응형