I have a table with columns name and full name, and am interested in knowing whether one is part of the other (but they are not equal).
Example:
name | full name | is_subset
-------------------------------------------
john smith | john smith | false
john smith | john h. smith | true
john smith | alice jones | false
I found a method that works using SPLIT and array intersections, but was curious as to whether there is a simpler or more efficient method.
SELECT
name,
full name,
CARDINALITY(
(
ARRAY_INTERSECT(
SPLIT(name, ' '),
SPLIT(full name, ' ')
)
)
) = CARDINALITY(SPLIT(name, ' ')) AND CARDINALITY(
SPLIT(full name, ' ')
) > CARDINALITY(SPLIT(name, ' ')) AS is_subset
from t
(name EXCEPT fullname) = [] AND (fullname EXCEPT name) != []a bbeing compared toa a b?a bbe considered a subset ofb a, as they're not equal?a bis equal toa a b. And similarly, since order doesn't count,a bequalsb a.