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

Do you know what are the restrictions that views have to follow?

0 Answers  


What is the difference between function and stored procedure in sql server?

0 Answers  


How to add a new column to an existing table with "alter table ... Add" in ms sql server?

0 Answers  


As a general practice, it is recommended to have dbo be the owner of all database objects however, in your database you find number of tables owned by a user other than dbo, how could you fix this?

0 Answers  


Write an sql query to sort a table according to the amounts in a row and find the second largest amount.

0 Answers   Amazon,






What is the use of partition by in sql server?

0 Answers  


What is coalesce and check constraint in sql server?

0 Answers  


If any possiable to use 2 primary key in single table? How many primary key & foreign key used in each table(min & max)?

3 Answers  


What are translations and its use? : sql server analysis services, ssas

0 Answers  


How to name query output columns in ms sql server?

0 Answers  


What is difference between joins and subqueries?

0 Answers  


Write a sql query to display the current date?

0 Answers  


Categories