By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,856 Members | 2,149 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,856 IT Pros & Developers. It's quick & easy.

HELP with sql query

P: 3
What I need is an SQL query that joins three tables. TableA and TableB are joined on Column1 which is common to both. Rows are filtered by Column2 in TableA equalling a specific value SpecificValue1. TableB and TableC are joined by Column3 which exists in both tables. However, I need all rows from TableB regardless of whether or not there is a corresponding row in TableC.

Up to there has been no problem. However, the monkey wrench is that from TableC I only want values if Column4 in TableC is a specific value SpecificValue2, otherwise I want it to return a Null value for that row.

Here is what I have and it does not produce the Nulls I am looking for. It only produces rows if TableC Column3's specific value exists for that particular row.

SELECT TableA.Column1, TableA.Column2, TableB.Column3, TableC.Column4, TableA Column5
FROM ((TableA INNER JOIN TableB ON TableA.Column1 = TableB.Column1) LEFT OUTER JOIN TableC ON TableB.Column3 = TableC.Column3) WHERE (TableA.Column2 = SpecificValue1) AND (Table3.Column4 = SpecificValue2) ORDER BY TableA.Column5

Any help would be appreciated.

By the way, here is the actual query if you are interested:

SELECT PARTSBOOKPAGEDETAIL.PB_ItemNo, PARTSBOOKPAGEDETAIL.PB_ItemSuffix, PARTSBOOKPAGEDETAIL.PB_Qty, PARTSBOOKPAGEDETAIL.PB_SKU, PRODUCTS.PR_Description, USER_DEF.UD_Searchable, PRODUCTS.PR_ProductID FROM ((PARTSBOOKPAGEDETAIL INNER JOIN PRODUCTS ON PARTSBOOKPAGEDETAIL.PB_SKU = PRODUCTS.PR_SKU) LEFT OUTER JOIN USER_DEF ON PRODUCTS.PR_ProductID = USER_DEF.UD_ProdID) WHERE (PARTSBOOKPAGEDETAIL.PBPD_Page = ?) AND (USER_DEF.UD_Index = 6) ORDER BY PARTSBOOKPAGEDETAIL.PB_ItemNo, PARTSBOOKPAGEDETAIL.PB_ItemSuffix
Apr 11 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.