by Dinesh Thakur Category: SQL Queries

Similar to the UNION command, INTERSECT also operates on two SQL statements. The difference is that, while UNION essentially acts as an OR operator (value is selected if it appears in either the first or the second statement), the INTERSECT command acts as an AND operator (value is selected only if it appears in both statements).

INTERSECT operator allows you to combine two table expressions into one and return a result set which consists of rows that appear in the results of both table expressions. INTERSECT operator, like UNION operator, removes all duplicated row from the result sets.

Syntax:
[SQL Statement 1]
INTERSECT
[SQL Statement 2]

SQL> SELECT ENANE, EMPNO FROM EMP WHERE ENAME LIKE'M%' OR ENAME LIKE 'J%';
INTERSECT
SELECT ENAME, EMPNO FROM EMP WHERE ENAME LIKE 'J%' OR ENAME LIKE 'A%';

On execution it will return the common rows that come in first select statement and also in second statement.

Related Articles of SQL


About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content