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 )
Create table #PassStudentID (id int not null )
SET DATEFORMAT DMY
insert into #student
Select 1 , 'A' , 'India' , '1-jan-2010', null union all
Select 2 , 'B' , 'India' , '1-jan-2012', null
insert into #PassStudentID
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