What is nested sub query and how to write query

Posted by Jitendrasoft09 under Sql Server on 6/26/2013 | Points: 10 | Views : 1787 | Status : [Member] [MVP] | Replies : 3
Hi All,
I want to understand What is nested sub query and how to write query, let me know if anybody knows.

Jitendra Kumar
If my post helps you, plz mark as an answer.



Responses

Posted by: Satyapriyanayak on: 6/26/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
http://msdn.microsoft.com/en-us/library/ms189575%28v=sql.105%29.aspx
https://www.simple-talk.com/content/article.aspx?article=1297

If this post helps you mark it as answer
Thanks

Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Saranya Boopathi on: 6/27/2013 [Member] Starter | Points: 25

Up
0
Down
Nested Query:There is no relationship between inner and outer query.

select * from Book_Imp_Det where book_id in
(Select b_id from Book_details )

Saranya Boopathi

Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neeraaj.Sharma on: 6/28/2013 [Member] Starter | Points: 25

Up
0
Down
Please mark as Answer if this help you know the concept

What is nested sub query and how to write query?

When the main query* needs some input from another query to get the final result without having any
relationship inside the subquery generally called subquery or Nested Subquery.


*Using to get the final output in the query referring the main query


let`s create a scenario where it required

there is a student table contains data from all students and
another table contain id for only passed students.

we want to see student details who are passed.



Create table #student (id int not null , name char(1) not null , address varchar(10) not null , joinDate date not null , remarks varchar(100) null )
GO
Create table #PassStudentID (id int not null )
Go



SET DATEFORMAT DMY
insert into #student
Select 1 , 'A' , 'India' , '1-jan-2010', null union all
Select 2 , 'B' , 'India' , '1-jan-2012', null
GO


insert into #PassStudentID
Select 2
GO


here is the solution using nested query:

Select * From #student where ID in
( Select ID from #PassStudentID )






Visit my blog
www.tutorialsqlserver.com

Jitendrasoft09, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response