BUG Fix data query not always joining necessary tables
Fixes #2846
Merge pull request #3019 from tractorcow/pulls/3.1-dataquery-tables

BUG Fix data query not always joining necessary tables