Skip to content

Commit 2f8791b

Browse files
committed
Update important.md
1 parent 345fa3f commit 2f8791b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

important.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@
22

33
<br/>
44

5-
## Q. What is difference between Co-related sub query and nested sub query?
5+
## Q. What is difference between Correlated subquery and nested subquery?
66

7-
- Correlated subquery executes single time for every row which is selected by the outer query.
8-
- It has a reference to a value from the row selected by the outer query.
9-
- Nested subquery executes only once for the entire nesting (outer) query. It does not contain any reference to the outer query row.
7+
Correlated subqueries are used for row-by-row processing. Each subquery is executed once for every row of the outer query.
108

11-
- For example,
12-
- Correlated Subquery:
9+
A correlated subquery is evaluated once for each row processed by the parent statement. The parent statement can be a SELECT, UPDATE, or DELETE statement.
10+
11+
**Example:**
12+
13+
```sql
14+
--- Correlated Subquery
1315
select e.EmpFirstName, e.Salary, e.DeptId from Employee e where e.Salary = (select max(Salary) from Employee ee where ee.DeptId = e.DeptId)
16+
```
1417

15-
- Nested Subquery:
18+
```sql
19+
--- Nested Subquery
1620
select EmpFirstName, Salary, DeptId from Employee where (DeptId, Salary) in (select DeptId, max(Salary) from Employee group by DeptId)
21+
```
1722

1823
<div align="right">
1924
<b><a href="#table-of-contents">↥ back to top</a></b>

0 commit comments

Comments
 (0)