Solved

Limiting a query based on entries in a table?

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
EditableGrid how to fetch rows from MySql in php 14 68
Need quicker response from an Execption table 11 43
How to trim a value in SQL 2 47
Need more granular date groupings 4 43
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.…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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