Solved

Unmatched Records for Specific Product ID Query

Posted on 2011-09-05
3
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

756 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