?
Solved

Match all fields against a lookup table

Posted on 2011-04-19
3
Medium Priority
?
481 Views
Last Modified: 2012-05-11
Hi Experts,

Forgive me if this is a basic question but I haven't been able to find a resource online that answers this.

I'm trying to apply an array of conditions to a SQL SP.  To do so I want to take a lookup table

RecipeID, CategoryID
1,1
1,2
2,1
2,2
2,3
2,5
3,4
4,1
4,2
4,3
4,4

and return the RecipeID's for all records that match ALL of the variables in a table variable

CategoryID
1
2
3

With results like:

Result
2
4


Any Hints?

Thanks!

Michael











0
Comment
Question by:mcunn
  • 2
3 Comments
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 2000 total points
ID: 35427333


select distinct RecipeID
from recepes
where CategoryID in (1,2,3)
0
 

Author Closing Comment

by:mcunn
ID: 35427461
Doh! Thanks! I was over thinking it with odd joins.
0
 

Author Comment

by:mcunn
ID: 35427549
Actually, this doesn't solve the issue...

This pulls ANY matches... I need it to pull matches that ALL fields match.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

839 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