Given these 2 tables
Table name: MyValues
| Id | IdValue |
| ------------ | ------------ |
| 1 | 10 |
| 2 | 10 |
| 3 | 10 |
| 1 | 11 |
Table name: MyConditions
Id | IdValue |
---|---|
7 | 10 |
7 | 11 |
How could I write a query to get the Ids from the MyValues table to return the ones that match all the records on MyConditions table where MyValues.IdValue = MyConditions.IdValue
So the result would be 1 (since Id 1 from MyValues table matches all records in MyConditions table)
1条答案
按热度按时间tjjdgumg1#
This reads like a relational division problem. We can join, and filter with
having
:This assumes no duplicate
(id, idvalue)
inmyvalue
, and no duplicateidvalue
inmycondition
. Otherwise, we would typically usedistinct
on one or both side ofhaving
: