Solved

Multiple outer joins in transact SQL

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating date based transactions 15 45
SQL find overlapping events (by time) 2 25
Using Aggregate Functions to Count 3 31
Need a starter for ETL protocol? 4 31
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

943 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

6 Experts available now in Live!

Get 1:1 Help Now