skip to Main Content

I want to select rows from a table where a column value lies in another column value of the same table.
I am trying to execute code in Oracle SQL developer

I have a larger input dataset similar to below :

keys val set
1 H H, L , M
2 L P, Q , R
3 P P, S

I want to select only those records where my val column value lies in the set column of the same table. There can be multiple or single values in the set column
The output would be like this :

keys val
1 H
3 P

How to achieve it using MySQL ? Please help.

**Note **: I have tried using below code. Its not working :

select keys, val
from a where val in (set)

3

Answers


  1. I think it’s need something like:

    SELECT keys, val FROM a WHERE SET='val'
    
    Login or Signup to reply.
  2. I think you should try this

    SELECT `keys`, `val` FROM `temp` WHERE FIND_IN_SET(`val`, `set`);
    
    Login or Signup to reply.
  3. you can do a simple comparison using concat :

    SELECT `keys`, val
    FROM dataset 
    where `set` like concat('%',val,'%');
    

    Try it here : https://dbfiddle.uk/HZ5spY-k

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search