Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the standard SQL Query to retrieve the intersection of tables?

Tags:

sql

Selecting the union:

select * from table1 
union 
select * from table1_backup 

What is the query to select the intersection?

like image 891
Peter Turner Avatar asked Sep 29 '08 14:09

Peter Turner


People also ask

How do you find the intersection of two tables in SQL Server?

Description. The SQL Server (Transact-SQL) INTERSECT operator is used to return the records that are in common between two SELECT statements or data sets. If a record exists in one query and not in the other, it will be omitted from the INTERSECT results. It is the intersection of the two SELECT statements.

What is an intersection table in SQL?

Intersection table. The intersection table holds the associations between rows in the base tables of the master and detail business components. Each row in the intersection table represents one association between the two business components.

Is INTERSECT standard SQL?

INTERSECT is not supported in every implementation of SQL, but it is the standard.

How do you do UNION and intersection in SQL?

The syntax for a set operation is: <SELECT-statement> {UNION | INTERSECT | EXCEPT | MINUS} [ALL | DISTINCT] <SELECT-statement> {UNION | INTERSECT | EXCEPT | MINUS} [ALL | DISTINCT] <SELECT-statement>]* [ORDER BY …] [LIMIT …]


1 Answers

In SQL Server intersect

select * from table1 
intersect
select * from table1_backup
like image 118
Tom Ritter Avatar answered Oct 06 '22 00:10

Tom Ritter