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.
STY: Fix spacing and line length
TST: Fix failing tests

See #465
Merge pull request #464 from ElDeveloper/query-inconsistency

BUG: Fix query that relied on insert order