0

Is it possible to compare two strings and find values not present in both? For example,

String 1: [email protected] [email protected]

String 2: [email protected] [email protected] [email protected] [email protected]

Result: [email protected]; [email protected]

Is it possible to use NOT IN or NOT EXISTS to capture those values.

Thanks for any direction.

1
  • 1
    No. NOT IN and NOT EXISTS do not do what you want at the string level. Commented Jul 21, 2020 at 14:48

1 Answer 1

1

You can use string_split() and aggregation:

select string_agg(coalesce(s1.value, s2.value), '; ')
from string_split(@string1, ' ') s1 full join
     string_split(@string2, ' ') s2
     on s1.value = s2.value
where s1.value is null or s2.value is null;

Here is a db<>fiddle.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.