BUG Fix data query not always joining necessary tables
Fixes #2846