Join 3 tables (table1, table2 & table3) in a single query.

Inner join should be applied for table1 & table 2 and left
outer join for table1 & table3 where table2.dept is ABC

Answers were Sorted based on User's Feedback



Join 3 tables (table1, table2 & table3) in a single query. Inner join should be applied for ..

Answer / dhanasekaran

select *
from table1 t1
inner join table2 t2 on t1.key = t2.key
left outer join table3 t3 on t1.key = t3.key
where t2.dept ='ABC'

Is This Answer Correct ?    11 Yes 0 No

Join 3 tables (table1, table2 & table3) in a single query. Inner join should be applied for ..

Answer / sumit m.

Although the above answer is correct. I am preferring
paranthesis in the answer, something like below:

There are 2 forms of the query for the answer:

SELECT *
FROM (table t1 INNER JOIN table2 t2 ON t1.col = t2.col AND
t2.dept = 'ABC')
LEFT JOIN table t3 ON t1.col = t3.col

OR

SELECT *
FROM (table t1 INNER JOIN (SELECT * FROM table2 WHERE dept
= 'ABC') t2 ON t1.col = t2.col)
LEFT JOIN table t3 ON t1.col = t3.col

Is This Answer Correct ?    6 Yes 0 No

Post New Answer

More SQL Server Interview Questions

What is measure group, measure? : sql server analysis services, ssas

0 Answers  


What is normalization? Explain its different types?

0 Answers   GE, Maveric,


What is the difference between a stored procedure and a user defined function?

0 Answers  


After recovering the database by using tail log backup.How to verify the data has been sucessfully restored or not.?

0 Answers   Cognizant,


Define tool Manage Statistics in SQL Server 2000 query ?

0 Answers   NA,






How to delete an existing row with delete statements in ms sql server?

0 Answers  


What are .mdf files?

0 Answers  


How to tune a stored procedure?

6 Answers  


What are the two virtual tables SQL Server maintains for triggers?

3 Answers  


how to determine the service pack currently installed on sql server? : Sql server database administration

0 Answers  


What is single-user mode?

0 Answers  


What is stretch database in sql server?

0 Answers  


Categories