# Fetch Only Common Records From Two Tables

In this blog, we will see how to fetch common records from two tables in SQL Server, which means the matching records of both the tables will be shown.

I have two tables, which are student and student1.

student
1. Select * from student

student1
1. Select * from student1

Query
1. (Select * from student) Intersect (Select * from student1)
Output

Now, you can see in both my tables that only common records are shown in our result set.

Explanation

In this query, we have used Intersect; if you have knowledge about Algebra, then you must know it well. If you don't know, don't worry about it, as I am explaning it.

Intersection

Intersecion works on more than one result set. Intersecion is denoted by ∩. Intersection A ∩ B of two
sets A and B is the set, which contains all the elements of A, which also belong to B (or equivalently, all elements
of B that also belong to A), but no other elements.

Let A={ Orange, pineapple, banana} and
Let B={ spoon,Orange, pineapple, mango}

A ∩ B = {Orange, pineapple}

Same thing happens in our SQL query but this process is hidden..