Solved

Need help with SQL Query and joins

Posted on 2008-06-18
1
412 Views
Last Modified: 2012-08-14
Greetings,

I am doing a query that should pull data from 2 related tables.  The relationship is based on both the Job-ID and System-ID being equal.  What I am getting with the below query is 4 results, when I run the query joined only to 1 table at a time I get back 1 result from the MatlUsageData table and 4 from the Production table.  My desired result set would be 5 rows, with the fields from the other table just blank.

Attached is a spreadsheet showing the current results and showing the desired results.  Any help would be appreciated.

Thanks,
John
SELECT     PUB.Job."Job-ID" AS Expr1, PUB.Job."Cust-ID-Bill-to", PUB.Job."Quotation-Amount", PUB.Job."System-ID" AS Expr2, 
                      PUB.MatlUsageData."Cost-Actual", PUB.MatlUsageData."Cost-Estimated", PUB.Production."Job-ID", PUB.Production."Sub-Job-ID", 
                      PUB.Production."System-ID", PUB.Production."Operation-ID", PUB.Production."Dept-ID", PUB.Production."Work-Center-ID", 
                      PUB.Production."Work-Center-Rate"
FROM         { oj { oj PUB.Job LEFT OUTER JOIN
                      PUB.MatlUsageData ON PUB.Job."Job-ID" = PUB.MatlUsageData."Job-ID" AND 
                      PUB.Job."System-ID" = PUB.MatlUsageData."System-ID" } LEFT OUTER JOIN
                      PUB.Production ON PUB.Job."Job-ID" = PUB.Production."Job-ID" AND PUB.Job."System-ID" = PUB.Production."System-ID" }
WHERE     (PUB.Job."Job-ID" = '280892') AND (PUB.Job."System-ID" = '2')

Open in new window

expertsexchangequeryresults.xls
0
Comment
Question by:rugby148
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 9

Accepted Solution

by:
Tone' Shelby earned 500 total points
ID: 21818186
Hi
Usually if they are of equal match, an INNER JOIN should do the match. If the idea here is that you are losing one record from your join and you have tried that, I would then try a RIGHT JOIN and if that does not bring back what you need, you may try approaching it from a UNION standpoint if that is an accepted option in your environment.
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

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.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

751 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