Nested SQL Query or SQL Sub Query

Nested SQL query :- 

if any SQL query is used according to any other SQL query then this type of SQL query is called sub-query. Nested query or inner query. It means if a select from where clause is used according to other select from where clause, then it is called nesting of query. Nested query is used to solve complex problems. Data provided by sub query is used in main query in form of condition. At the time of writing of sub query following rules are applied -
1. sub query is always written according to parenthesis.
2. according to sub query only the value of a column is written.
3. sub query doesn't use order by in place of it group by is used etc.

Syntax :- 
select column_name1, column_name2,... from table1 where column_name op (select column_name from table2 where predicate);

we learn following customers table to understand sub query -

Customers Table

Example :- 

select * from customers where ID IN (select ID from customers where salary>40000);

ID
Name
Salary
1
Teena
50,000
2
Deepak
70,000
5
Aakash
55,000

No comments:

Post a Comment

Nested SQL Query or SQL Sub Query in hindi in english

if a SQL query is used inside another SQL query then this type of SQL query is called sub-query.  यदि किसी SQL क्वेरी का उपयोग, किसी अन्य SQ...