select rows from key-list in a single column
I've got to do research in a database system where fore开发者_JAVA技巧ign keys for an 1:n relationship are stored as comma separated list in a single column. I want to do a query which prints out every row from table A where the primary key is found in a certain column of table B, but I just don't get how to do it. The database used is oracle 10, if that helps.
You want to use the INSTR function.
Select A.*
FROM Foo A
Where A.ID IN
(SELECT A.ID FROM Bar B
Where INSTR(','||B.ConcatKeyField||',', ','||A.ID||`,', 1, 1) > 0)
A very crude, inefficient but simple way:
select ... from a, b
where instr(','||b.csvcol||',', ','||a.pk||',') > 0;
精彩评论