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
I think it’s need something like:
I think you should try this
you can do a simple comparison using
concat
:Try it here : https://dbfiddle.uk/HZ5spY-k