Solved

Limiting a query based on entries in a table?

Posted on 2008-10-29
2
173 Views
Last Modified: 2012-05-05
I have the following:

Select O.ID,O.EndDate,fs.fieldid,fs.type,fs.fieldvalue,fs.description
from Objects O
Inner JOIN metadata fs on fs.ID = O.ID
Inner JOIN DestructionList MS ON  ms.ID = O.ID
where O.Status = 5 AND MS.ID IS NOT NULL AND fs.Type = 'DataTable'

I have 3 tables

Objects
Metadata
DestructionList

The destructionlist tracks the ObjectID and a value for that object which is to be detroyed.

Objects & MetaData stores information.

So what I am trying to do is to join

Objects & MetaData where ID's match

and then join DestructionList where the ID or the Value are not contained within the destructionlist. There are instances where I may have multiple ObjectID's which are the same, but the value's are different, so I need to make sure that I show objects which are not in the destructionlist.

Any help would be much appreciated.
0
Comment
Question by:directxBOB
2 Comments
 
LVL 5

Accepted Solution

by:
jfmador earned 500 total points
ID: 22833338
if you want to get the Objects that are not in DestructionList, you can use a left join between the two table and after the join get only the rows where your DestructionListID is null

Select O.ID,O.EndDate,fs.fieldid,fs.type,fs.fieldvalue,fs.description
from Objects O
Inner JOIN metadata fs on fs.ID = O.ID
LEFT JOIN DestructionList MS ON  ms.ID = O.ID
where O.Status = 5 AND MS.ID IS NULL AND fs.Type = 'DataTable'
0
 

Author Comment

by:directxBOB
ID: 22839010
Select O.ID,O.EndDate,fs.fieldid,fs.type,fs.fieldvalue,fs.description
from Objects O
Inner JOIN metadata fs on fs.ID = O.ID
LEFT JOIN DestructionList MS ON  ms.ID = O.ID and MS.fieldId = fs.FieldID
where O.Status = 5 AND MS.FieldID IS NULL AND fs.Type = 'DataTable'

Cheers for the help, I was just missing two parts. One in the left join where I am joining on both fields, and then in the where .

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error converting data type nvarchar to bigint. 2 68
SQL Subquery Syntax Assistance 13 49
how to fix this error 14 57
SQL query 4 46
In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

948 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