If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Sql Query: trouble joining

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-11-04, 16:59
lauramccord lauramccord is offline
Registered User
 
Join Date: May 2004
Posts: 105
Sql Query: trouble joining

I need to combine these two queries where the second query will just be another column with in the first query. I want all the results from the first query displayed despite any conditions that were placed on the second query.

Code:
SELECT     PR.WBS1, PR.WBS2, PR.WBS3, LB.AmtBud
FROM         PR LEFT OUTER JOIN
                      LB ON LB.WBS1 = PR.WBS1 AND LB.WBS2 = PR.WBS2 AND LB.WBS3 = PR.WBS3
WHERE     (PR.WBS1 = '001-298') AND (PR.WBS3 <> 'ZZZ')
ORDER BY PR.WBS2, PR.WBS3

SELECT     PR.WBS1, PR.WBS2, PR.WBS3, SUM(LD.BillExt) AS Expr1
FROM         PR LEFT OUTER JOIN
                      LD ON LD.WBS1 = PR.WBS1 AND PR.WBS2 = LD.WBS2 AND PR.WBS3 = LD.WBS3
WHERE     (PR.WBS1 = '001-298') AND (PR.WBS3 <> 'ZZZ') AND (LD.BilledPeriod = '200408')
GROUP BY PR.WBS1, PR.WBS2, PR.WBS3
ORDER BY PR.WBS2, PR.WBS3
Any suggestions?

Thanks
Reply With Quote
  #2 (permalink)  
Old 11-11-04, 17:11
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Code:
SELECT PR.WBS1
     , PR.WBS2
     , PR.WBS3
     , LB.AmtBud
     , ( select SUM(LD.BillExt) 
           from LD 
          where WBS1 = PR.WBS1 
            AND WBS2 = PR.WBS2
            AND WBS3 = PR.WBS3 
            and BilledPeriod = '200408' ) as Expr1
  FROM PR 
LEFT OUTER 
  JOIN LB 
    ON LB.WBS1 = PR.WBS1 
   AND LB.WBS2 = PR.WBS2 
   AND LB.WBS3 = PR.WBS3
 WHERE (PR.WBS1 = '001-298') 
   AND (PR.WBS3 <> 'ZZZ')
ORDER 
    BY PR.WBS2
     , PR.WBS3
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On