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 |
What are the magic tables in SQL Server 2000?
7 Answers Infogain, Merrill Lynch,
What do you understand by replication in sql server?
What is difference between inner join and full join?
What is t-sql script to take database offline – take database online.
What is difference between Datepart() and Datename() in SqlServer?
What is the maximum row of a size?
How you can change the database name in SQL SERVER?
How you can move data or databases between servers and databases in sql server?
How to find tables without indexes?
What is an index in a database?
Difference between writing SQL query and stored procedure ?
15 Answers Cognizant, Infosys, TCS, Veritas,
logshipping is Any difference 2000 and 2005?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)