Solved

Limiting a query based on entries in a table?

Posted on 2008-10-29
2
174 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Query still returning duplicates 5 27
How to update the value of duplicated records (except latest one) 2 18
Access 2003 query lost it's only join 7 26
SQL Error - Query 6 24
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

13 Experts available now in Live!

Get 1:1 Help Now