Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 query

Author  Topic 

Kevin007
Starting Member

3 Posts

Posted - 2002-03-22 : 16:42:48
Hi Developers,

I need help. I have two tables. How do you query for (CLASS2_ID or CLASS1_ID or CLASS3_ID)= 100 and (CLASS2_ID or CLASS1_ID or CLASS3) = 200? These two numbers need to be in the product or else I don't want to display the product. Is there a way to do this?

SELECT DISTINCT
INGREDIENT_NAME,
CLASS2_ID,
CLASS1_ID,
CLASS3_ID,
ING_ID
FROM FDA INNER JOIN
ING ON
FDA.ING_ID = ING.ING_ID
WHERE (product_ID= 11482)

Thank You,
Kevin


robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-03-22 : 16:57:19
The IN function will do the trick:

SELECT DISTINCT INGREDIENT_NAME, CLASS2_ID, CLASS1_ID, CLASS3_ID, ING_ID
FROM FDA INNER JOIN ING ON FDA.ING_ID = ING.ING_ID
WHERE (product_ID= 11482)
AND 100 IN (CLASS1_ID, CLASS2_ID, CLASS3_ID)
AND 200 IN (CLASS1_ID, CLASS2_ID, CLASS3_ID)


This is reversed from the normal usage of IN; most examples use a single column to search, but multiple values...i.e. WHERE LastName IN ('Smith', 'Jones', 'Brown')...but it should still work for you.

Go to Top of Page

Kevin007
Starting Member

3 Posts

Posted - 2002-03-22 : 17:23:28
Hi Robvolk,

Thank you so much!!


Kevin

Go to Top of Page
   

- Advertisement -