Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need help with SQL Query and joins

Posted on 2008-06-18
1
Medium Priority
?
416 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
1 Comment
 
LVL 9

Accepted Solution

by:
Tone' Shelby earned 1500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
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…
Suggested Courses

916 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