Solved

Limiting a query based on entries in a table?

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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.…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

16 Experts available now in Live!

Get 1:1 Help Now