Make the JOIN query