GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Tech FAQs  >  SQL Server

 Print  |  
Question:  Subqueries vs Joins in SQL

Answer: What is the difference between Subqueries and Joins? Which is better and Why? Give an example of each.


August 08, 2008 08:09:42 #2
 sakthi.jaganathan   Member Since: August 2008    Total Comments: 7 

RE: Subqueries vs Joins in SQL
 
Join is a Methodology to get a data from more than one table, its work under the condition.

Example:

If we want to display the Employee no and his Department no

SELECT Empno,Deptno
FROM Emp,Dept
where Emp.Deptno=Dept.Deptno

subquery it has two select statement, the inner select statement will execute first and then it will be the value for outer select statement.


Example:

If we want to display the employees who are getting salary more than an employee TIM

SELECT Ename,Sal
FROM Emp
WHERE Sal>(SELECT Sal
FROM Emp
WHERE Ename='TIM');
     

 

Back To Question