$res = $this->fetchRow(
                $this->select()
                    ->setIntegrityCheck(false)
                    ->from(['u' => $this->getTableName()])
                    ->joinLeft(['fr' => $this->_dbprefix.'relations'], '(fr.sender = u.userid OR fr.receiver = u.userid) AND status = 2', new \Zend_Db_Expr('COUNT(DISTINCT fr.relation_id) AS friendscount'))