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
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 |
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 |
Do you know what are the restrictions that views have to follow?
What is the difference between function and stored procedure in sql server?
How to add a new column to an existing table with "alter table ... Add" in ms sql server?
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?
Write an sql query to sort a table according to the amounts in a row and find the second largest amount.
What is the use of partition by in sql server?
What is coalesce and check constraint in sql server?
If any possiable to use 2 primary key in single table? How many primary key & foreign key used in each table(min & max)?
What are translations and its use? : sql server analysis services, ssas
How to name query output columns in ms sql server?
What is difference between joins and subqueries?
Write a sql query to display the current date?