Tuesday , June 19 2018
Home / DataBase / SQL SERVER / SUB QUERIES

SUB QUERIES

Subqueries:-
1.A query inside another query is known as subquery.
2.First inner query is executed then result of inner query is input for outer query.
3.Outer can be insert/update/delete/select
4.inner query must be always select.
Types of Subqueries:-
1.single row subquery
2.Multirow Subquery
3.Co-related Subquery

Sample Tables:

Table 1:EMPLOYEE

Table 2: DEPARTMENT

1.single row subquery:-
If Subquery returns only one value then it is called singlerow subquery.

Example:

 

2.Multirow Subquery:-
If inner Query returns more than one value then it is called Multirow Subquery.

op must be IN,NOT IN,ANY,ALL

Example:

3.Co-related Subquery:-
If inner query takes values from outer query then it is called Co-related Subquery.
–>Execution starts from outer query and inner query not just executed once,executed no.of times.
–>If the table contains 6 records then inner query executes 6 times i.e depends on no.of records.
Print Friendly, PDF & Email

Give us your valuable feedback

comments

About Samba

Check Also

Find all rows count and columns count in single database in sql server

In General for any database it contains lot of tables, if we want to find …

%d bloggers like this: