How to run a LIKE query with multiple values?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Marcin W

    How to run a LIKE query with multiple values?

    Hi,

    I have following problem. I have to run a query where one of the result fields should be within range of values I got from different table.

    Query 1

    select column_x from table1 where filed_x = 'Y'

    this query gives me 33 different alphanumeric values

    Query 2

    select column1,
    column2,
    column3
    from table2 where
    column3 like '%ONE OF VALUES FROM QUERY1'

    I am quite fresh in SQL and I really need help with this one. The problem is, that column3 in table2 can hold not only the exact values received from query1, but also values from query1 with little prefixes. Do you know any way to get this working?

    Thanks for any comments. MArcin
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    Maybe like that
    Code:
    select table2.column1,
    table2.column2,
    table2.column3
    from table2,table1 where
    table1.filed_x = 'Y'
    and
    table2.column3 like '%'||table1.column_x;
    o to chodziło :) ?

    Comment

    • amitpatel66
      Recognized Expert Top Contributor
      • Mar 2007
      • 2358

      #3
      Try this:

      [code=oracle]

      SELECT t2.column1,
      t2.column2,
      t2.column3
      FROM table1 t1,table2 t2
      WHERE INSTR(t2.column 3,t1.column_x,1 ,1) > 0
      AND t1.field_x = 'Y'
      /
      [/code]

      Comment

      Working...