Solved

Help with SQL Syntax (Join Issue)

Posted on 2011-03-22
2
275 Views
Last Modified: 2012-05-11
I need some help wtih the following SQL query. It works find if there is at least one row/result in each of the joined tables. I discovered that on the first two joins dbo.objects_geography and dbo.object_geography can have nulls on a given o.id in the WHERE clause.

How do I fix this so that even if dbo.objects_geography and dbo.object_geography have nulls in them, it will still return the rest of the data?

I'm thinking I need to modify my joins, but realize I need some help in this area.

Thanks.
SELECT o.id, o.title, o.display_date, o.medium, o.dimensions, o.credit_line, o.invno, 
og2.country, og2.city, m.filename, m.primary_display
FROM dbo.objects o
INNER JOIN dbo.objects_geography og1 ON o.id = og1.object_id 
INNER JOIN dbo.object_geography og2 ON og2.id = og1.geography_id
INNER JOIN dbo.objects_media om ON o.id = om.object_id
INNER JOIN dbo.media m ON om.media_id = m.id
WHERE o.id = 4250893

Open in new window

0
Comment
Question by:greddin
2 Comments
 
LVL 5

Accepted Solution

by:
simonpaul64 earned 500 total points
ID: 35194028
SELECT o.id, o.title, o.display_date, o.medium, o.dimensions, o.credit_line, o.invno,
og2.country, og2.city, m.filename, m.primary_display
FROM dbo.objects o
LEFT OUTER JOIN dbo.objects_geography og1 ON o.id = og1.object_id
LEFT OUTER JOIN  dbo.object_geography og2 ON og2.id = og1.geography_id
INNER JOIN dbo.objects_media om ON o.id = om.object_id
INNER JOIN dbo.media m ON om.media_id = m.id
WHERE o.id = 4250893
0
 

Author Closing Comment

by:greddin
ID: 35194134
Thanks for the help! Works great now.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

864 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

21 Experts available now in Live!

Get 1:1 Help Now