SQL stands for Structured Query Language. Client can compose SQL script to execute and SQL compiler consequently produces a method to get to database and convey the fancied output. SQL is a database coding, planned for the recuperation and organisation of data in social database.
SQL Intersect operator is used for returning records from multiple select query. It returns only records in common between the Select statements. It omits the records which are present in one select query and not in other select query. And the column parameters specifies the name of the columns of the table and the datatypes parameters specifies the type of data that the column is holding that may varies from varchar, decimal, date and integers.
Conceptual
figure
Syntax
The syntax for Intersect is as follows:
SELECT column1, column2.....columnN FROM <table_name>..... WHERE <search_condition> INTERSECT SELECT column1, column2.....columnN FROM <table_name>..... WHERE <search_condition>;
Table name =>The accurate table name in the database.
Columns => The conditions that can be performed on a column in the table.
Examples
The below example, describes the execution of Intersect command.
[c]
sql> select * from employee;
+--------+-------+-------+
| emp_id | ename |salary |
+--------+-------+-------+
| 1001 | jack | 12000 |
| 1002 | mack | 13000 |
| 1003 | james | 15000 |
| 1004 | Kim | 17000 |
+--------+-------+-------+
4 rows in set (0.00 sec)
sql> select * from employer;
+--------+-------+-------+
| emp_id | ename |salary |
+--------+-------+-------+
| 100 | jacky | 10000 |
| 1002 | mack | 13000 |
| 101 | Kate | 16000 |
| 1004 | Kim | 17000 |
+--------+-------+-------+
4 rows in set (0.00 sec)
Select emp_id, ename, sal from employee
Intersect
Select emp_id, ename, salary from employer
+--------+-------+-------+
| emp_id | ename |salary |
+--------+-------+-------+
| 1002 | mack | 13000 |
| 1004 | Kim | 17000 |
+--------+-------+-------+
2 rows in set (0.00 sec)
[/c]
Summary
Key Points
SQL INTERSECT Command - Is used for returning records from multiple select query.