BUG: Fix query that relied on insert order

Creating a meta-analysis was broken because one of the central queries that
builds the metadata for the meta-analysis, relied on the fact an id imposed by
a study would be the same for sample and raw data tables.

This has been corrected, the query now retrieves the data correctly.