ERROR: syntax error at or near "AND" LINE 1: ...ers.id = units.primary_agent_id WHERE units.id = AND (units... ^