Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What is a regular subquery?


Asked by Andrea Peters on Dec 12, 2021 FAQ



A subquery is a regular SELECT statement nested inside another query such as SELECT, UPDATE or DELETE statement. The following picture illustrates the subquery concept: A subquery is also known as inner select or inner query, while the query that contains the subquery is called outer select or outer query.
One may also ask,
“Subquery is Query within a query in which the value of inner query is assigned to the outer query and outer query is executed…” When Query within a query or subquery returns only one row then these type of queries are called as single row subqueries.
Thereof, On the other hand regular or non-correlated subquery return a result which is then used by the outer query. It only executed one time and not for every row returned by the outer query, hence it is faster than a correlated subquery. Additionally, what is difference between subquery and join? Joins versus Subqueries.
Subsequently,
In a SQL database query, a correlated subquery (also known as a synchronized subquery) is a subquery (a query nested inside another query) that uses values from the outer query. Again, because the subquery is correlated with a column of the outer query, it must be re-executed for each row of the result.
Also,
If the output of Inner query count is more than 1 then these subqueries are called as multi row subqueries.We need to use ANY,IN,EXIST Operator in outer query of multi row subqueries because output of outer query is not a single value. Fetch the list of Employees which is assigned to ‘OBIEE’ and ‘Oracle’ Department.