Docsity

Understanding Non-correlated and Correlated Subqueries in SQL, Apuntes de Informática

Toggle sidebar
bg1
Non-correlated and correlated subqueries
When we create subqueries, we find that there are non-correlated and correlated subqueries.
in this essay, we will explain the differences between each of these queries.
The former is executed independently of the outer query. So, the subquery is executed first and
then passes its results to the other (Noncorrelated and correlated subqueries, n.d.) . Also, it is
used with the IN and NOT IN clauses, differing in that they are faster than the correlated
subqueries (Shriv, n.d.).
The second one depends on the other query, however, this one does not need the IN and NOT
IN clauses (Shriv, n.d.). being dependent it cannot run by itself, so it is dependent. another
difference is that they are slower than the non-correlated queries.
An example of a non-correlated query is when we want to find all the stocks of some country,
so we analyze that we may need to make queries from 2 different tables, being this a case in
which the non-correlated query is necessary (Paul, n.d.).
Another example related to correlated subqueries is related to when we want to find the
products whose price list is equal to the highest price list because in that case, we will need a
correlated subquery. (SQL Server correlated subquery, 2018)
Finally, we found that there are differences between both types of subqueries, so it is
important to understand in which situations they could be useful.
References
Noncorrelated and correlated subqueries. (n.d.). Vertica.Com. Retrieved June 12, 2022, from
https://www.vertica.com/docs/9.3.x/HTML/Content/Authoring/AnalyzingData/Queries/
Subqueries/NoncorrelatedAndCorrelatedSubqueries.htm
Paul, J. (n.d.). How to write SubQuery in SQL? Correlated vs noncorrelated sub query example.
Blogspot.Com. Retrieved June 12, 2022, from
https://javarevisited.blogspot.com/2012/07/subquery-example-in-sql-correlated-vs.html
Shriv, H. (n.d.). Difference between correlated and non-collreated subqueries in SQL.
Tutorialspoint.Com. Retrieved June 12, 2022, from https://www.tutorialspoint.com/difference-
between-correlated-and-non-collreated-subqueries-in-sql
SQL Server correlated subquery. (2018, May 8). SQL Server Tutorial.
https://www.sqlservertutorial.net/sql-server-basics/sql-server-correlated-subquery/

Vista previa parcial del texto

¡Descarga Understanding Non-correlated and Correlated Subqueries in SQL y más Apuntes en PDF de Informática solo en Docsity!

Non-correlated and correlated subqueries When we create subqueries, we find that there are non-correlated and correlated subqueries. in this essay, we will explain the differences between each of these queries. The former is executed independently of the outer query. So, the subquery is executed first and then passes its results to the other (Noncorrelated and correlated subqueries, n.d.). Also, it is used with the IN and NOT IN clauses, differing in that they are faster than the correlated subqueries (Shriv, n.d.). The second one depends on the other query, however, this one does not need the IN and NOT IN clauses (Shriv, n.d.). being dependent it cannot run by itself, so it is dependent. another difference is that they are slower than the non-correlated queries. An example of a non-correlated query is when we want to find all the stocks of some country, so we analyze that we may need to make queries from 2 different tables, being this a case in which the non-correlated query is necessary (Paul, n.d.). Another example related to correlated subqueries is related to when we want to find the products whose price list is equal to the highest price list because in that case, we will need a correlated subquery. (SQL Server correlated subquery, 2018) Finally, we found that there are differences between both types of subqueries, so it is important to understand in which situations they could be useful. References Noncorrelated and correlated subqueries. (n.d.). Vertica.Com. Retrieved June 12, 2022, from https://www.vertica.com/docs/9.3.x/HTML/Content/Authoring/AnalyzingData/Queries/ Subqueries/NoncorrelatedAndCorrelatedSubqueries.htm Paul, J. (n.d.). How to write SubQuery in SQL? Correlated vs noncorrelated sub query example. Blogspot.Com. Retrieved June 12, 2022, from https://javarevisited.blogspot.com/2012/07/subquery-example-in-sql-correlated-vs.html Shriv, H. (n.d.). Difference between correlated and non-collreated subqueries in SQL. Tutorialspoint.Com. Retrieved June 12, 2022, from https://www.tutorialspoint.com/difference- between-correlated-and-non-collreated-subqueries-in-sql SQL Server correlated subquery. (2018, May 8). SQL Server Tutorial. https://www.sqlservertutorial.net/sql-server-basics/sql-server-correlated-subquery/