UPDATED: Removed duplicated conditions in the JOIN clauses