Solved

Need help with SQL Query and joins

Posted on 2008-06-18
1
411 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 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error in my cursor 5 41
average of calculation (TSQL) 4 26
Check ALL SP in database make sure there are no errors 17 46
Access join syntax when converting to T-SQL query 4 37
Read about achieving the basic levels of HRIS security in the workplace.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

820 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