If you can 'fix' your table structure to have a 1:many relationship, such that each row in your subidtable
contains only one id
, that's your best bet.
If you can't, then you could get hold of one of the many split()
functions that people have coded around the web. These take a string and return the data as a set. The problem here is that they are designed to take a single string and return a table of values, not to take a table of strings...
As this data seems to be in a bit of a hacked format, you may only need a one-time hack solution with minimal code. In such cases you can try this...
SELECT
*
FROM
table
WHERE
EXISTS (SELECT * FROM subidtable WHERE (',' || subid || ',') LIKE ('%,' || table.id || ',%'))
But be warned, it scales VERY badly. So expect slow performance if you have a large amount of data in either table.
EDIT
As your edit now shows that you're only ever processing one string from the subidtable
table, the split function option becomes a lot easier to implement. See Justin's answer :)
A modification to the 'simple hack' above would be...
SELECT
*
FROM
table
WHERE
(SELECT ',' || subid || ',' FROM subidtable WHERE empno=1) LIKE ('%,' || table.id || ',%')