INTERSECT Operator in SQL Server
The INTERSECT operator is one of the Set Operators in SQL Server which is used to filter out duplicates and return only distinct rows of data. The INTERSET operator combines two or more SELECT statements and returns a single dataset with common and distinct data between the SELECT statements on the right and the left of the INTERSECT operator.
INTERSECT Syntax:
{ <query_specification> | ( <query_expression> ) }
{ INTERSECT }
{ <query_specification> | ( <query_expression> ) }
- query_specification or query_expression is a SELECT statement with or without a where clause.
- INTERSECT is the operator used to filter distinct or unique data common to the queries specified.
SQL Server INTERSECT and EXCEPT Operator
Multiple SQL Queries may return duplicate values in recordsets from each query result. There could be situations when a single resultset is needed to be returned by combining multiple SQL queries. In SQL Server, there are many SET operators like UNION, EXCEPT, and INTERSECT to merge multiple results of select statements to a single result set. The INTERSECT operator is one of them which is used to filter distinct values.
Structured Query Language (SQL) is a powerful tool for managing and manipulating relational databases. In SQL Server, various operators allow you to perform different types of set operations on your data. Two such operators are EXCEPT
and INTERSECT
, which are used to compare and combine the results of two queries.
Contact Us