-2

I have a table, which contains below values(small snap of data):

Row#| Column A | Column B
--------------------------
1   |A         | A,B
2   |C         | A,D
3   |M         | Z
4   |C         |A,B,L
5   |F         |F
6   |C         |O

List goes on and on. Column A and B is populated by other application, so its combinations are not predictable. Table has more than 4000 rows.

My search values are not fixed; I have to use search value from Column B of same row for which I am looking for data in Column A.

I want to check Column A's value is IN Column B or not. Basically compare Column A with B, if find match in B result should skip that row.

In above case Row#1's Column A's value is in B which is not true for row#2.

My query should reach all rows and compare Column A with B. Query should return Row#1 and 5

This question is different Using the "IN" clause with a comma delimited string from the output of a replace() function in Oracle SQL As it has fixed set of search value

Community
  • 1
  • 1
Soni Snehal
  • 47
  • 1
  • 1
  • 7
  • I dont have any solution, I tried regexpr with connect but I didnt get desired output. I don't have any clue to resolve it – Soni Snehal Dec 05 '16 at 20:59

1 Answers1

1
select * from my_table where instr(columnB, columnA) > 0;

Example: Should contain

select * from (
    select 1 a, 'A' b, 'A,B' c from dual union all
    select 2, 'C', 'A,D' from dual ) t
where instr(c,b) > 0;

Result:

A   B   C
-----------
1   A   A,B

Example 2: Shouldn't contain

select * from (
    select 1 a, 'A' b, 'A,B' c from dual union all
    select 2, 'C', 'A,D' from dual ) t
where instr(c,b) = 0;

Result:

A   B   C
-----------
2   C   A,D
Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76