user14826807
user14826807

Reputation:

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 :))

Upvotes: 0

Views: 63

Answers (1)

Stu
Stu

Reputation: 32609

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) ;

Demo DB<>Fiddle

Upvotes: 1

Related Questions