Difference between correlated and non-collreated subqueries in SQL


SQL query is used to fetch data from the database. In some of the scenario you may need some perquisite data to call subsequent SQL query to fetch data from a table so instead of writing two seperate query we can write SQL query within the query.Therefore subQuery is a way to combine or join them in single query. Subqurey can have two types −

  • Correlated subquery - In correlated subquery, inner query is dependent on the outer query. Outer query needs to be executed before inner query
  • Non-Correlated subquery - In non-correlated query inner query does not dependent on the outer query. They both can run separately.
Sr. No.KeyCorrelated subqueryNon-Correlated subquery

1

Basic 

In correlated subquery, inner query is dependent on the outer query

 In non-correlated query inner query does not dependent on the outer query

2

IN and NOT In clause 


It does not use IN and NOT In clause 

 Non-Correlated subquery are used along-with IN and NOT IN clause

3

Run Separately 

Inner query can not run alone 

Inner query can not run alone and it's not depended on outer query 


4

Performance 

correlated subqueries are slower queries 

They are faster than correlated subqueries


Updated on: 21-Jan-2020

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements