Solved

Multiple outer joins in transact SQL

Posted on 1998-07-17
1
299 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now