Your example isn’t entirely clear but from what I gather, it sounds like you want to run a custom select query. See this for reference:
Scroll down to where you see:
"Query based on Custom Field and Category"
Is this along the lines of what you are looking for?