简体   繁体   中英

How to return values from table B by looking up comma separated values in a column in table A

I am not sure if my question makes sense but I will try to explain here. I have two tables

TABLE SAM (SR PK,CODE) . Column CODE may or may not contain comma separated values.

表SAM

TABLE FOO (CODE_VAL PK, CODE_DISP_TX)

餐桌椅

I want to write a select query to give me following output from FOO WHERE SAM.SR = 3

产量

Fix your data model! Storing lists as strings is a really, really bad idea.

Sometimes, we are stuck with other people's really, really bad decisions. You can do:

select f.*
from foo f
where exists (select 1
              from sam s
              where ',' || code || ',' like '%,' || f.code || ',%'
             );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM