Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 subqueries

Author  Topic 

kshitizgp
Starting Member

31 Posts

Posted - 2011-12-15 : 03:34:52
There are three broad divisions of subquery:

Single-row subqueries
Multiple-row subqueries
Correlated subqueries


can u guyz explain with simple examples plsssssssssss ..... thnx alot for ur this forum :)

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-15 : 03:40:18
the names itself are self explanatory
single row subquery returns a single row of data to query of which its a part.
multiple row subqueries as name implies returns a resultset and in most cases will end in a cross join (cartesian product) with rest of query part unless you specify relation on basis of on condition
correlated subquery involves relating the subquery with main query part using column or columns which will be passed into subquery and will do checking inside

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2011-12-15 : 03:43:53
Single row subqueries

Select * from table_name where id=(Select id from table_name where primary_key_column = 1)

Multiple-row subqueries


Select * from table_name where column_name in (select column_name from table_name)


Correlated subqueries


Seelct t1.col1,t2.col1 from t1 inner join
(Select col1,col2,col3 from table )t2 on t1.col1=t2.col1


Senthil Kumar C
------------------------------------------------------
MCITP - Database Administration SQL SERVER 2008
MCTS - Database Development SQL SERVER 2008
Go to Top of Page
   

- Advertisement -