0

I have the following code:

with my_table (id, col_1, col_2)
as (values 
(1, '$ (USD)', '$ (USD) million'),
(2, '$ (USD)', '$ (USD)'),
(3, 'USD', '$ (USD)'),
(4, 'EUR', '$ (USD)')
)

select *,
     case when col_1 = col_2 then 'TRUE'
     else 'FALSE'
     end as is_a_match
from my_table

the output:

id   col_1      col_2              is_a_match
1    $ (USD)    $ (USD) million    FALSE
2    $ (USD)    $ (USD)            TRUE
3    USD        $ (USD)            FALSE
4    EUR        $ (USD)            FALSE

how can I edit the query so I get id 1,2,3 as TRUE and id 4 as FALSE? I would like it to be generic, so if there are other currencies it can also look for a partial match.

1 Answer 1

2

You can use strpos() to check if the string in col_1 occurs anywhere in col_2:

select *,
       strpos(col_2, col_1) > 0 as is_a_match
from my_table
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.