SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SubQuery
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

asif372
Posting Yak Master

Pakistan
100 Posts

Posted - 04/25/2013 :  02:57:26  Show Profile  Reply with Quote

Can any one explain me sub query in easy words ? i am new in sql

bandi
Flowing Fount of Yak Knowledge

India
2210 Posts

Posted - 04/25/2013 :  03:09:17  Show Profile  Reply with Quote
If you want to get results based on the output of another query, then sub queries will be used.
You can use sub queries in the SELECT, FROM, WHERE.... clauses
Ex:
SELECT EMPLOYEE_ID, SALARY, FIRST_NAME || ' ' || LAST_NAME "Highest Paid Employee"
FROM EMPLOYEES
WHERE SALARY = (SELECT MAX (SALARY) FROM EMPLOYEES) -- this is the sub query for getting highest salary of employees

refer these links for further details:
https://www.simple-talk.com/sql/sql-training/subqueries-in-sql-server/
http://msdn.microsoft.com/en-IN/library/ms189575(v=sql.105).aspx
http://blog.sqlauthority.com/2010/06/06/sql-server-subquery-or-join-various-options-sql-server-engine-knows-the-best/

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 04/25/2013 :  04:16:01  Show Profile  Reply with Quote
another type of subqueries are correlated subqueries where you pass column(s) from main query to it and retrieve related data from one or more tables based on passed column values

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000