'SQL: Check if Table is subset of another Table
Does anyone know how to Filter from two tables(A,B) all the tuples which are a full subset of the other table?
So I want to filter all the matrnr from Table A which contains both of the values of Table B.
So the result should be: 4321
Example:
TABLE A:
| matrnr | lvanr |
|---|---|
| 4321 | 1234 |
| 4321 | 4321 |
| 1234 | 5431 |
TABLE B:
| lvanr |
|---|
| 1234 |
| 4321 |
Thanks for help :))
Solution 1:[1]
You can outer join the tables and filter on matching counts, does the following work for you?
select a.matrnr
from TablaA a
left join TableB b on a.ivanr = b.ivanr
group by a.matrnr
having Count(a.matrnr) = Count(b.ivanr) ;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
