INTERSECT Clause:
It works similar like union clause as it is used to combine two SELECT statements, but it returns tuples only from first SELECT statement which are common to tuples in the second SELECT statement.
Syntax:
SELECT column(s)
FROM table1
WHERE condition
INTERSECT
SELECT column(s)
FROM table2
WHERE condition;
Example:
SELECT EmpID, EmpNAME, EmpSalary
FROM Employee
INTERSECT
SELECT ID, NAME, Salary
FROM Employee1;
The above query will select those emploee id,name salary which are common in both tables.
Every SQL statement written in a SQL INTERSECT must have the same number of fields in the result sets with same data types.
0 Comment(s)