I have tables like this:
table 1:
| FNAME | ID1 | FID |
|---|---|---|
| BREAD | XYZ | 18BREAD |
| FISH | ABC | 45FISH |
| BREAD_OLD | BNQ | 18BREAD_OLD |
| BACON | TBG | 77BACON |
| EGGS | CGS | 99EGGS |
| BANANA | BHG | BANANA18 |
table 2:
| FNAME | FID |
|---|---|
| BREAD | 18 |
| FISH | 45 |
| BACON | 77 |
| EGGS | 99 |
currently a simple search is done on table 1 to find id's of food as follows:
SELECT ID1
FROM TABLE1
WHERE NAME IN NAME_LIST
so for example when the name list is: ('BREAD','FISH') then it returns XYZ, ABC. The problem is this misses 'BREAD_OLD' which is an older version with the same ID. (18)
I need to change this so now the search is done based on the FID of food rather than the NAME to find affected foods but I cannot change the input.
eg: given a list of foods: ('BREAD', 'FISH')
the result should be XYZ, ABC, BNQ (because BREAD matches 18 which matches BNQ in table 1)
how can this can be done? I think I need to use a join or do a 'select within a select' but I'm not sure how this would work with multiple inputs.
edit: ORACLE is the database edit 2: adding BANANA18 to table 1, needs to be leading match
@xto notify one non-sole non-poster commenterxre a comment. Posters, sole commenters & followers of posts always get notified.