Solved

Unmatched Records for Specific Product ID Query

Posted on 2011-09-05
3
232 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

708 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