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 −
Sr. No. | Key | Correlated subquery | Non-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 |