Hello,
I believe this post may relate to what you need: Can you do a conditional selection from one table to another?