does your function return id or pallet?...this would possibly provide a "join"
maybe better if you posted create table/insert sample data scripts and your expected results...am sure this will result is a tried and tested answer for you.
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day