• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

Find matching records

I have a table that stores and OP_ORG_ID, OP_ID and ORG_ID associated with each OP_ID.

An example would be like
OP_ORG_ID, OP_ID, ORG_ID
114, 12345, 10
115, 12345, 40

I want to be able to query the table and find all instances where an OP_ID has both ORG_ID 10 and 40 associated to it
0
bhinshawnc1
Asked:
bhinshawnc1
1 Solution
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
Hope this helps you out
SELECT OP_ID
FROM urtable
WHERE ORG_ID IN ( 10, 40) 
GROUP BY OP_ID
HAVING COUNT(ORG_ID) = 2

Open in new window

0
 
ajexpertCommented:
Your question is not clear.  Do you have multiple tables having OP_ID column?
Can you provide more data and table structures?
0
 
bhinshawnc1Author Commented:
Thanks, this got me going in the right direction as part of a larger query I was building.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now