views:

55

answers:

0

Suppose I run k-many sub-queries against e.g. tables in a database(s), and the results from each query share a common field e.g. a string, or uuid value, which shares meaning across these tables.

Assuming I can have the queries returned sorted, are there API's which exists in languages already which allow me to find the intersection of the separate queries, based on this common field?

I haven't picked a language yet. Ideally, I would want to use this intersection as a cacheable result, and then return it as a new object, along with the results of the subqueries.

Additionally, I would like to find the values of the common field which occur most frequently amongst all the subqueries.

Within each result set, the common field will not be repeated.

Thank you in advance for any direction.

UPDATE WITH EXAMPLE:

An analogy would be if I were searching for all people who watch Family Guy (FG), and watched Harry Potter and the Order of the Phoenix (HP), and who visited 7-eleven on Thursday (SE).

Well, my data sources may be separate, so this isn't one big super query SQL I can feed in. But suppose that each result set is sorted by person's first name, and we're working with a world of unique first names.

Maybe Alice and Bob are in result sets FG, HP, and SE. Woo!

But maybe the intersection of FG, HP, and SE on First Name is empty.

Can I find who's in the most categories?