- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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. | 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 |