Skip to content
Advertisement

How to select rows from table 2 based on values in column from table 1 in SQL Teradata?

I have table in SQL Teradata:

client              | description
--------------------|-----------
John Simon          |arg John Simon
Larry Foe           |Larry Foe por
Judy Gap            |payment 11 

And I need to find only these clients which has their name (from column “client”) + “arg” or “por” in column “descpition” nevermind whether before or after name. So using above example I need to display only John Simon and Larry Fore, because they have their name in column “description + “arg” or “por” nevermind whether before or after name.

How can I do that?

Advertisement

Answer

One method is:

where description like '%' || client || '%' and
      (' ' || description || ' ' like '% por %' or
       ' ' || description || ' ' like '% org %'
      )

The delimiters in the second part are just to avoid matches for a name like “Portland”.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement