Solved

Multiple outer joins in transact SQL

Posted on 1998-07-17
1
316 Views
Last Modified: 2010-03-19
I have a multi-table database (aren't they all) which requires several outer join statements and we are piecing it together by the key columns.  Can someone give me an example of a SQL statement which incorporates multiple outer joins.
Maybe using the famous "Pubs" database MS uses.

Thanks Heaps, buckets, and chick peas.
0
Comment
Question by:oldmanbran
1 Comment
 
LVL 1

Accepted Solution

by:
Staplehead earned 10 total points
ID: 1091786
well, i don't have that DB on my machine here, but assume the following db:

employees: nbr, last_name, first_name
offices: nbr, bldg, room, emp_nbr
computers: nbr, manufacturer, model, tag, emp_nbr

to list employees, their offices, and what computer(s) they have:

SELECT employees.first_name, employees.last_name, offices.bldg, offices.room, computers.manufacturer, computers.model, computers.tag
FROM (employees OUTER JOIN offices ON employees.nbr=offices.emp_nbr) OUTER JOIN computers ON computers.emp_nbr=employees.nbr
ORDER BY employees.last_name, employees.first_name;

not a big example, but you get the idea; if you need more tables, you can just keep cascading them.  keep in mind that if, for example, the left side of a join is the result of another join and the right side is a new table, then one of your "ON" fields is from the original set of tables (on the left) and the other is from the new table..

Larry
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question