Data

Matching, Not Matching

We can further combine relations.

Matching (semijoin)

To check which tuples from one relation have tuples with common attribute(s) present in another we can use &~ (or if your keyboard can create it) to match them.

S
SNOSNAMESTATUSCITY
S1Smith20London
S2Jones10Paris
S3Blake30Paris
S4Clark20London
S5Adams30Athens
SP
SNOPNOQTY
S1P1300
S1P2200
S1P3400
S1P4200
S1P5100
S1P6100
S2P1300
S2P2400
S3P2200
S4P2200
S4P4300
S4P5400
S &~ SP
SNOSNAMESTATUSCITY
S1Smith20London
S2Jones10Paris
S3Blake30Paris
S4Clark20London

This is similar to the often-used WHERE EXISTS (subselect) in SQL, e.g. SELECT DISTINCT * FROM S WHERE EXISTS (SELECT 1 FROM SP WHERE SP.SNO = S.SNO)

Not Matching (semiminus / antijoin)

We can find ones not present using -&~ (or if your keyboard can create it).

S -&~ SP
SNOSNAMESTATUSCITY
S5Adams30Athens

This is similar to the often-used WHERE NOT EXISTS (subselect) in SQL.

Matching and Not Matching are not commutative, but they do have reverse counterparts: ~& and ~&- (or and ).