MAKE FULL WEB APPLICATION WITH JUST SQL KNOWLEDGE? CLICK HERE
The INTERSECT query allows you to return the results of two
or more "select" queries. However, it only returns
the rows selected by all queries. If we want to know all those employees
who are working in both the department then we will have to use
the intersect operator. Intersect gives a single set of records
which are common in both the queries.
The syntax for an INTERSECT query is :-
select field1, field2, . field_n
from tables
INTERSECT
select field1, field2, . field_n
from tables;
|
EXAMPLE I:-
Let's assume that we have the following two tables,
Table Store Information :-
STORE NAME |
SALES |
DATE |
Tantra Guys Collection |
$2500 |
Sep-01-2006 |
Kashish Saree Centere |
$9000 |
Sep-10-2006 |
Tantra Guys Collection |
$2300 |
Sep-20-2006 |
Positive Store |
$6300 |
Sep-26-2006 |
Table Internet :-
SALES DATE
|
SALES
|
Sep-05-2006
|
$1200
|
Sep -07-2006
|
$2500
|
Sep-26-2006
|
$6300
|
Sep-28-2006
|
$7800
|
We want to find out all the dates where there are both store sales
and internet sales.
The following SQL statement :-
SELECT Date FROM Store_Information INTERSECT
SELECT Date FROM Internet_Sales
|
RESULTS:-
Note:-The INTERSECT command will only return distinct values.
If you don't find what you are looking for. Please click
here to submit your query, our experts will reply soon.
|