Sql Intersect Operator


The SQL INTERSECT operator is used to return the rows that are in common between two result sets.

If a row exists in one result set and not in the other, it will be ignored or omitted by the operator in the final results.

The two queries must result in the same number of columns and compatible data types in order to combine.


Search Keys

  • sql intersect vs join
  • sql intersect example
  • sql intersect vs union
  • sql intersect operator
  • sql intersect query
  • sql intersect command
  • sql intersect mysql
  • sql intersect all example
  • sql intersect and except
  • sql intersect count
  • sql intersect columns
  • sql conditional intersect
  • sql intersect multiple columns
  • sql intersect one column
  • sql intersect except
  • sql intersect equivalent

Sql Intersect Syntax

The below syntax is used to create intersect operator with select statements.


SELECT column-name1, column-name2, ... column-nameN 
FROM table-name 
[WHERE conditions]

INTERSECT

SELECT column-name1, column-name2, ... column-nameN 
FROM table-name 
[WHERE conditions]

Note:-
  • There must be same number of columns and order in both SQL SELECT statements.
  • The corresponding columns in each of the SELECT statements must have similar or compatiable data types.

Sample Database Table - EmpInfo

ID EmpName Gender Age City
1 Rishi Keshan Male 22 Aruppukoottai
5 Chandra Female 24 Mysore
6 Hari Krishnan Male 28 Hyderbhad

Sample Database Table - EmpInfo2

ID EmpName Gender Age City
1 Rishi Keshan Male 22 Aruppukoottai
2 Bala Murugan Male 31 Pune
3 Ranjani Mai Female 32 Aruppukoottai

SQL Intersect Operator Example

The following SQL statement will display common records from both tables.


SELECT * FROM EmpInfo
INTERSECT
SELECT * FROM EmpInfo2

The result of above query is:

ID EmpName Gender Age City
1 Rishi Keshan Male 22 Aruppukoottai

Search Keys

  • sql intersect except union
  • sql intersect example oracle
  • sql intersect error
  • sql intersect empty
  • sql intersect except all
  • sql intersect minus except
  • sql intersect minus
  • sql intersect multiple tables
  • sql intersect mariadb
  • sql intersect multiple queries
  • sql intersect ms access
  • sql intersect multiple
  • sql intersect where clause
  • sql intersect with join
  • sql intersect with null
  • sql intersect not working
  • sql intersect without intersect