Solved

Unmatched Records for Specific Product ID Query

Posted on 2011-09-05
3
233 Views
Last Modified: 2012-05-12
Experts,

I am at a total loss! I cannot figure out the correct syntax for a query that is trying to find unmatched records.

I have the following tables:

tblProductPrice
PK: CostID
Lng: SiteID
Lng: TTechID


tblWebsite
PK: WebsiteID
Str: WebAddress

The query will have a particular TTechID that it needs to find any WebsiteID's that are not in the tblProductPrice.SiteID for that specific TTechID.

I've tried the following sql
SELECT tblWebsite.WebAddress
FROM tblWebsite
WHERE NOT EXISTS (SELECT SiteID FROM tblProductPrice WHERE tblProductPrice.SiteID = tblWebsite.WebsiteID)

Open in new window


and

 
SELECT tblWebsite.WebAddress
FROM tblWebsite LEFT JOIN tblProductPrice ON tblWebsite.WebsiteID = tblProductPrice.SiteID
WHERE (((tblProductPrice.SiteID) Is Null));

Open in new window


Neither of these work correctly specifically because they don't have any reference to the TTechID in question.

Please help me add whatever conditional statement is needed to refine the query search to the specific TTechID in question.

Thank you!
0
Comment
Question by:w00tw00t111
3 Comments
 
LVL 22

Accepted Solution

by:
Thomasian earned 500 total points
ID: 36486376
SELECT tblWebsite.WebAddress
FROM tblWebsite
WHERE NOT EXISTS (SELECT SiteID FROM tblProductPrice WHERE tblProductPrice.SiteID = tblWebsite.WebsiteID
                                                           AND tblProductPrice.TTechID=1)

Open in new window

SELECT tblWebsite.WebAddress
FROM tblWebsite LEFT JOIN tblProductPrice ON (tblWebsite.WebsiteID = tblProductPrice.SiteID
                                             AND tblProductPrice.TTechID=1)
WHERE tblProductPrice.SiteID Is Null

Open in new window

0
 
LVL 4

Expert Comment

by:AnuTiji
ID: 36486804
Hi

Please find the query below
DECLARE @TTechID INT
SET @TTechID =1
SELECT 
	websiteId, 
	webaddress 
	FROM tblWebsite 
	WHERE WebsiteID not in 
		(
			SELECT siteid 
			FROM tblProductPrice 
			WHERE TTechID=@TTechID
		)

Open in new window

0
 

Author Closing Comment

by:w00tw00t111
ID: 36490369
Perfect! Thank you!

So simple...but staring at it for hours I couldn't see it. Thank you very much.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

930 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now