builds the sql query for the GetItemName method that is usual used as callback in the GetOptions method
we only want to show results that are values of the selected shop attribute in the filter item.

@return string
774433
protected function GetSQLQueryForQueryRestrictionForActiveFilter()
    {
        $dStartValue = $this->GetActiveStartValue();
        $dEndValue = $this->GetActiveEndValue();
        $sQuery = '';
        if (false !== $dStartValue && false !== $dEndValue) {
            $sEscapedTargetTable = MySqlLegacySupport::getInstance()->real_escape_string($this->sItemTableName);
            $sEscapedTargetMLTTable = MySqlLegacySupport::getInstance()->real_escape_string('shop_article_'.$this->sItemTableName.'_mlt');
            $oShopAttribute = $this->GetFieldShopAttribute();

            $sQuery = "SELECT `{$sEscapedTargetMLTTable}`.*
                     FROM `{$sEscapedTargetTable}`
               INNER JOIN `{$sEscapedTargetMLTTable}` ON `{$sEscapedTargetTable}`.`id` = `{$sEscapedTargetMLTTable}`.`target_id`
                    WHERE ".$this->GetTargetTableNameField().' >= '.MySqlLegacySupport::getInstance()->real_escape_string($dStartValue).'
                      AND '.$this->GetTargetTableNameField().' <= '.MySqlLegacySupport::getInstance()->real_escape_string($dEndValue)."
                      AND `{$sEscapedTargetTable}`.`shop_attribute_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($oShopAttribute->id)."'";
        }

        return $sQuery;
    }
570851
private function getItemSelectQuery(): QueryBuilder
    {
        $query = $this->connection->createQueryBuilder();
        $query->select('DISTINCT ngbm_collection_item.*')
            ->from('ngbm_collection_item');

        return $query;
    }
1106068
public function getFilterPreselect()
    {
        // get definitions from plugin settings
        // and proceed only when preselectedFilter was not set
        // this reduces the amount of sql queries, too
        if ($this->conf['preselected_filters'] && count($this->preselectedFilter) == 0) {
            $preselectedArray = GeneralUtility::trimExplode(',', $this->conf['preselected_filters'], true);
            foreach ($preselectedArray as $option) {
                $option = intval($option);
                $queryBuilder = Db::getQueryBuilder('tx_kesearch_filters');
                $pageRepository = GeneralUtility::makeInstance(PageRepository::class);
                $filterRows = $queryBuilder
                    ->add(
                        'select',
                        '`tx_kesearch_filters`.`uid` AS filteruid, `tx_kesearch_filteroptions`.`uid` AS optionuid, `tx_kesearch_filteroptions`.`tag`'
                    )
                    ->from('tx_kesearch_filters')
                    ->from('tx_kesearch_filteroptions')
                    ->add(
                        'where',
                        'FIND_IN_SET("' . $option . '",tx_kesearch_filters.options)'
                        . ' AND `tx_kesearch_filteroptions`.`uid` = ' . $option
                        . $pageRepository->enableFields('tx_kesearch_filters')
                        . $pageRepository->enableFields('tx_kesearch_filteroptions')
                    )
                    ->execute()
                    ->fetchAll();

                foreach ($filterRows as $row) {
                    $this->preselectedFilter[$row['filteruid']][$row['optionuid']] = $row['tag'];
                }
            }
        }
    }
520950
protected function _getQuery()
    {
        $myConfig = \OxidEsales\Eshop\Core\Registry::getConfig();
        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
        // looking for table/view
        $sArtTable = $this->_getViewName('oxarticles');
        $sView = $this->_getViewName('oxobject2category');

        $sSelId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('oxid');
        $sSynchSelId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('synchoxid');

        // category selected or not ?
        if (!$sSelId) {
            //performance
            $sQAdd = " from $sArtTable where 1 ";
            $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? '' : " and $sArtTable.oxparentid = '' ";
        } else {
            // selected category ?
            if ($sSynchSelId && $sSelId != $sSynchSelId) {
                $sQAdd = " from {$sView} left join $sArtTable on ";
                $blVariantsSelectionParameter = $myConfig->getConfigParam('blVariantsSelection');
                $sSqlIfTrue = " ( $sArtTable.oxid={$sView}.oxobjectid or $sArtTable.oxparentid={$sView}.oxobjectid) ";
                $sSqlIfFalse = " $sArtTable.oxid={$sView}.oxobjectid ";
                $sQAdd .= $blVariantsSelectionParameter ? $sSqlIfTrue : $sSqlIfFalse;
                $sQAdd .= " where {$sView}.oxcatnid = " . $oDb->quote($sSelId);
            } else {
                $sQAdd = " from {$sArtTable} left join oxactions2article " .
                         "on {$sArtTable}.oxid=oxactions2article.oxartid " .
                         " where oxactions2article.oxactionid = " . $oDb->quote($sSelId) .
                         " and oxactions2article.oxshopid = '" . $myConfig->getShopID() . "' ";
            }
        }

        if ($sSynchSelId && $sSynchSelId != $sSelId) {
            $sQAdd .= " and {$sArtTable}.oxid not in ( select oxactions2article.oxartid from oxactions2article " .
                      " where oxactions2article.oxactionid = " . $oDb->quote($sSynchSelId) .
                      " and oxactions2article.oxshopid = '" . $myConfig->getShopID() . "' ) ";
        }

        return $sQAdd;
    }
143099
protected function _getQuery()
    {
        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
        $sArtId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('oxid');
        $sSynchArtId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('synchoxid');

        $sAttrViewName = $this->_getViewName('oxattribute');
        $sO2AViewName = $this->_getViewName('oxobject2attribute');
        if ($sArtId) {
            // all categories article is in
            $sQAdd = " from {$sO2AViewName} left join {$sAttrViewName} " .
                     "on {$sAttrViewName}.oxid={$sO2AViewName}.oxattrid " .
                     " where {$sO2AViewName}.oxobjectid = " . $oDb->quote($sArtId) . " ";
        } else {
            $sQAdd = " from {$sAttrViewName} where {$sAttrViewName}.oxid not in ( select {$sO2AViewName}.oxattrid " .
                     "from {$sO2AViewName} left join {$sAttrViewName} " .
                     "on {$sAttrViewName}.oxid={$sO2AViewName}.oxattrid " .
                     " where {$sO2AViewName}.oxobjectid = " . $oDb->quote($sSynchArtId) . " ) ";
        }

        return $sQAdd;
    }
446785
public function getQuery()
    {
        $sql = $this->prepareSelectString();
        $sql .= $this->prepareJoinString();
        $sql .= $this->prepareWhereString();
        $sql .= $this->prepareGroupByString();
        $sql .= $this->prepareHavingString();
        $sql .= $this->prepareOrderByString();
        $sql .= $this->prepareLimitString();

        return $sql;
    }
815081
public function GetQueryRestrictionForActiveFilter()
    {
        $sQuery = parent::GetQueryRestrictionForActiveFilter();
        if (is_null($sQuery)) {
            $aValues = $this->aActiveFilterData;
            if (is_array($aValues) && count($aValues) > 0) {
                $quotedItemFieldName = $this->getDatabaseConnection()->quoteIdentifier($this->sItemFieldName);
                $sQuery = " `shop_article`.$quotedItemFieldName = '' ";
            }
        }

        return $sQuery;
    }
511070
public function buildSelectSQL()
	{
		$where = $this->parseCondition(isset($this->operationOption['where']) ? $this->operationOption['where'] : '');
		if ('' !== $where)
		{
			$where = 'where ' . $where . ' ';
		}
		return 'select ' . $this->parseDistinct()
				. $this->parseFieldBefore()
				. $this->parseField(null,'*')
				. 'from '
				. $this->parseTable() . ' '
				. $this->parseJoin()
				. $where
				. $this->parseGroup()
				. $this->parseHaving()
				. $this->parseOrder()
				. $this->parseLimit()
				. $this->parseLock()
				;
	}
357169
public function GetQueryRestrictionForActiveFilter()
    {
        $sQuery = $this->GetFromInternalCache('sQueryRestrictionForActiveFilter');
        if (is_null($sQuery)) {
            $aValues = $this->aActiveFilterData;
            if (!is_array($aValues)) {
                if (empty($aValues)) {
                    $aValues = array();
                } else {
                    $aValues = array($aValues);
                }
            }
            if (count($aValues) > 0) {
                $aValues = TTools::MysqlRealEscapeArray($aValues);
                //          $oVariantType = $this->GetVariantType();

                $sItemListQuery = "SELECT DISTINCT `shop_article`.`variant_parent_id`
                      FROM `shop_variant_type_value`
                INNER JOIN `shop_article_shop_variant_type_value_mlt` ON `shop_variant_type_value`.`id` = `shop_article_shop_variant_type_value_mlt`.`target_id`
                INNER JOIN `shop_article` ON `shop_article_shop_variant_type_value_mlt`.`source_id` = `shop_article`.`id`
                INNER JOIN `shop_article` AS PARENTARTICLE ON `shop_article`.`variant_parent_id` = PARENTARTICLE.`id`
                INNER JOIN `shop_variant_type` ON `shop_variant_type_value`.`shop_variant_type_id` = `shop_variant_type`.`id`
                     WHERE (`shop_variant_type_value`.`name` IN ('".implode("','", $aValues)."') OR `shop_variant_type_value`.`name_grouped` IN ('".implode("','", $aValues)."'))
                       AND `shop_variant_type`.`identifier` = '".MySqlLegacySupport::getInstance()->real_escape_string($this->sVariantTypeIdentifier)."'
                       AND PARENTARTICLE.`active` = '1'
                   ";
                $sActiveRestrictions = TdbShopArticleList::GetActiveArticleQueryRestriction(false);
                if (!empty($sActiveRestrictions)) {
                    $sItemListQuery .= ' AND ('.$sActiveRestrictions.')';
                }
                $tRes = MySqlLegacySupport::getInstance()->query($sItemListQuery);
                //echo $sItemListQuery;echo "\n\n";
                $aIdList = array();
                while ($aItemRow = MySqlLegacySupport::getInstance()->fetch_assoc($tRes)) {
                    $aIdList[] = MySqlLegacySupport::getInstance()->real_escape_string($aItemRow['variant_parent_id']);
                }

                if (count($aIdList) > 0) {
                    $sQuery = "`shop_article`.`id` IN ('".implode("','", $aIdList)."')";
                }
            }

            $this->SetInternalCache('sQueryRestrictionForActiveFilter', $sQuery);
        }

        return $sQuery;
    }
654066
public function GetQueryRestrictionForActiveFilter()
    {
        $sQuery = '';
        $dStartValue = $this->GetActiveStartValue();
        $dEndValue = $this->GetActiveEndValue();
        if ($dStartValue > 0 && $dEndValue > 0) {
            $sQuery = "`shop_article`.`{$this->sItemFieldName}` >= '".MySqlLegacySupport::getInstance()->real_escape_string(
                $dStartValue
            )."' AND `shop_article`.`{$this->sItemFieldName}` <= '".MySqlLegacySupport::getInstance()->real_escape_string($dEndValue)."'";
        } elseif ($dStartValue > 0) {
            $sQuery = "`shop_article`.`{$this->sItemFieldName}` >= '".MySqlLegacySupport::getInstance()->real_escape_string($dStartValue)."'";
        } elseif ($dEndValue > 0) {
            $sQuery = "`shop_article`.`{$this->sItemFieldName}` <= '".MySqlLegacySupport::getInstance()->real_escape_string($dEndValue)."'";
        }

        return $sQuery;
    }
824864
public function GetOptions()
    {
        $aOptions = $this->GetFromInternalCache('aOptions');
        if (is_null($aOptions)) {
            if (PKG_SHOP_LISTFILTER_ENABLE_COUNT_PER_FILTER_ITEM) {
                $oObj = clone $this->oItemListFilteredByOtherItems;
                $iCount = $this->oItemListFilteredByOtherItems->Length();
                $databaseConnection = $this->getDatabaseConnection();
                $quotedItemFieldName = $databaseConnection->quoteIdentifier($this->sItemFieldName);
                $oObj->AddFilterString(" `shop_article_stock`.$quotedItemFieldName > 0");
                $iWithStockCount = $oObj->Length();
                $aOptions[0] = $iCount - $iWithStockCount;
                $aOptions[1] = $iWithStockCount;
            } else {
                $aOptions[0] = 1;
                $aOptions[1] = 1;
            }
            $this->SetInternalCache('aOptions', $aOptions);
        }

        return $aOptions;
    }
1251966
protected function GetSQLQueryForQueryRestrictionForActiveFilter()
    {
        $sItemListQuery = parent::GetSQLQueryForQueryRestrictionForActiveFilter();
        $quotedItemTableName = $this->getDatabaseConnection()->quoteIdentifier($this->sItemTableName);
        $sItemListQuery .= " AND $quotedItemTableName.`shop_attribute_id` = '".MySqlLegacySupport::getInstance()->real_escape_string(
                $this->fieldShopAttribute
            )."'";

        return $sItemListQuery;
    }
198520
protected function _getQuery()
    {
        $myConfig = \OxidEsales\Eshop\Core\Registry::getConfig();
        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();

        // looking for table/view
        $sArtTable = $this->_getViewName('oxarticles');
        $sO2CView = $this->_getViewName('oxobject2category');

        $sDelId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('oxid');
        $sSynchDelId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('synchoxid');

        // category selected or not ?
        if (!$sDelId) {
            // performance
            $sQAdd = " from $sArtTable where 1 ";
            $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? '' : "and $sArtTable.oxparentid = '' ";
        } else {
            // selected category ?
            if ($sSynchDelId && $sDelId != $sSynchDelId) {
                $sQAdd = " from $sO2CView left join $sArtTable on ";
                $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? " ( $sArtTable.oxid=$sO2CView.oxobjectid or $sArtTable.oxparentid=$sO2CView.oxobjectid)" : " $sArtTable.oxid=$sO2CView.oxobjectid ";
                $sQAdd .= "where $sO2CView.oxcatnid = " . $oDb->quote($sDelId);
            } else {
                $sQAdd = ' from oxobject2delivery left join ' . $sArtTable . ' on ' . $sArtTable . '.oxid=oxobject2delivery.oxobjectid ';
                $sQAdd .= 'where oxobject2delivery.oxdeliveryid = ' . $oDb->quote($sDelId) . ' and oxobject2delivery.oxtype = "oxarticles" ';
            }
        }

        if ($sSynchDelId && $sSynchDelId != $sDelId) {
            $sQAdd .= 'and ' . $sArtTable . '.oxid not in ( ';
            $sQAdd .= 'select oxobject2delivery.oxobjectid from oxobject2delivery ';
            $sQAdd .= 'where oxobject2delivery.oxdeliveryid = ' . $oDb->quote($sSynchDelId) . ' and oxobject2delivery.oxtype = "oxarticles" ) ';
        }

        return $sQAdd;
    }
847602
protected function _getQuery()
    {
        // looking for table/view
        $sArtTable = $this->_getViewName('oxarticles');
        $sO2CView = $this->_getViewName('oxobject2category');
        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();

        // category selected or not ?
        if ($sSynchOxid = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('synchoxid')) {
            $sQAdd = " from $sArtTable left join $sO2CView on $sArtTable.oxid=$sO2CView.oxobjectid where $sO2CView.oxcatnid = " . $oDb->quote($sSynchOxid);
            if ($aSkipArt = \OxidEsales\Eshop\Core\Registry::getSession()->getVariable('neworder_sess')) {
                $sQAdd .= " and $sArtTable.oxid not in ( " . implode(", ", \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->quoteArray($aSkipArt)) . " ) ";
            }
        } else {
            // which fields to load ?
            $sQAdd = " from $sArtTable where ";
            if ($aSkipArt = \OxidEsales\Eshop\Core\Registry::getSession()->getVariable('neworder_sess')) {
                $sQAdd .= " $sArtTable.oxid in ( " . implode(", ", \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->quoteArray($aSkipArt)) . " ) ";
            } else {
                $sQAdd .= " 1 = 0 ";
            }
        }

        return $sQAdd;
    }
404014
protected function _getQuery()
    {
        $myConfig = \OxidEsales\Eshop\Core\Registry::getConfig();
        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();

        $sArticleTable = $this->_getViewName('oxarticles');
        $sOCatView = $this->_getViewName('oxobject2category');
        $sOAttrView = $this->_getViewName('oxobject2attribute');

        $sDelId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('oxid');
        $sSynchDelId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('synchoxid');

        // category selected or not ?
        if (!$sDelId) {
            // performance
            $sQAdd = " from $sArticleTable where 1 ";
            $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? '' : " and $sArticleTable.oxparentid = '' ";
        } elseif ($sSynchDelId && $sDelId != $sSynchDelId) {
            // selected category ?
            $blVariantsSelectionParameter = $myConfig->getConfigParam('blVariantsSelection');
            $sSqlIfTrue = " ( {$sArticleTable}.oxid=oxobject2category.oxobjectid " .
                          "or {$sArticleTable}.oxparentid=oxobject2category.oxobjectid)";
            $sSqlIfFalse = " {$sArticleTable}.oxid=oxobject2category.oxobjectid ";
            $sVariantSelectionSql = $blVariantsSelectionParameter ? $sSqlIfTrue : $sSqlIfFalse;
            $sQAdd = " from {$sOCatView} as oxobject2category left join {$sArticleTable} on {$sVariantSelectionSql}" .
                     " where oxobject2category.oxcatnid = " . $oDb->quote($sDelId) . " ";
        } else {
            $sQAdd = " from {$sOAttrView} left join {$sArticleTable} " .
                     "on {$sArticleTable}.oxid={$sOAttrView}.oxobjectid " .
                     "where {$sOAttrView}.oxattrid = " . $oDb->quote($sDelId) .
                     " and {$sArticleTable}.oxid is not null ";
        }

        if ($sSynchDelId && $sSynchDelId != $sDelId) {
            $sQAdd .= " and {$sArticleTable}.oxid not in ( select {$sOAttrView}.oxobjectid from {$sOAttrView} " .
                      "where {$sOAttrView}.oxattrid = " . $oDb->quote($sSynchDelId) . " ) ";
        }

        return $sQAdd;
    }
984175
public function GetOptions()
    {
        $aOptions = $this->GetFromInternalCache('aOptions');
        if (is_null($aOptions)) {
            $aOptions = array();
            $sIdSelect = $this->GetResultSetBaseQuery();

            $databaseConnection = $this->getDatabaseConnection();
            $quotedTargetTableNameField = $databaseConnection->quoteIdentifier($this->GetTargetTableNameField());

            if (PKG_SHOP_LISTFILTER_ENABLE_COUNT_PER_FILTER_ITEM) {
                $sItemQuery = "SELECT `shop_variant_type_value`.{$quotedTargetTableNameField} AS attribute, COUNT(`shop_variant_type_value`.{$quotedTargetTableNameField}) as matches
                FROM `shop_variant_type_value`
          INNER JOIN `shop_article_shop_variant_type_value_mlt` ON (`shop_variant_type_value`.`id` = `shop_article_shop_variant_type_value_mlt`.`target_id` AND `shop_variant_type_value`.`shop_variant_type_id` IN (".$this->getVariantTypeIds()."))
          INNER JOIN `shop_article` ON `shop_article_shop_variant_type_value_mlt`.`source_id` = `shop_article`.`id`
          INNER JOIN ($sIdSelect) AS PARENTS ON `shop_article`.`variant_parent_id` = PARENTS.`id`
               WHERE ".TdbShopArticleList::GetActiveArticleQueryRestriction(false)."
               GROUP BY `shop_variant_type_value`.{$quotedTargetTableNameField}
                ";
            } else {
                $sItemQuery = "SELECT DISTINCT `shop_variant_type_value`.{$quotedTargetTableNameField} AS attribute, 1 as matches
                FROM `shop_variant_type_value`
          INNER JOIN `shop_article_shop_variant_type_value_mlt` ON (`shop_variant_type_value`.`id` = `shop_article_shop_variant_type_value_mlt`.`target_id` AND `shop_variant_type_value`.`shop_variant_type_id` IN (".$this->getVariantTypeIds()."))
          INNER JOIN `shop_article` ON `shop_article_shop_variant_type_value_mlt`.`source_id` = `shop_article`.`id`
          INNER JOIN ($sIdSelect) AS PARENTS ON `shop_article`.`variant_parent_id` = PARENTS.`id`
               WHERE ".TdbShopArticleList::GetActiveArticleQueryRestriction(false).'
                ';
            }

            $tRes = MySqlLegacySupport::getInstance()->query($sItemQuery);
            while ($aOption = MySqlLegacySupport::getInstance()->fetch_assoc($tRes)) {
                $aOptions[$aOption['attribute']] = $aOption['matches'];
            }
            $this->OrderOptions($aOptions);
            $this->SetInternalCache('aOptions', $aOptions);
        }

        return $aOptions;
    }
1331938
protected function _getQuery()
    {
        $myConfig = \OxidEsales\Eshop\Core\Registry::getConfig();
        $sArticleTable = $this->_getViewName('oxarticles');
        $sView = $this->_getViewName('oxobject2category');

        $sSelId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('oxid');
        $sSynchSelId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('synchoxid');
        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();

        // category selected or not ?
        if (!$sSelId) {
            $sQAdd = " from {$sArticleTable} where 1 ";
            $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? '' : " and {$sArticleTable}.oxparentid = '' ";
        } elseif ($sSynchSelId && $sSelId != $sSynchSelId) {
            // selected category ?
            $blVariantsSelectionParameter = $myConfig->getConfigParam('blVariantsSelection');
            $sSqlIfTrue = " ({$sArticleTable}.oxid=oxobject2category.oxobjectid " .
                          "or {$sArticleTable}.oxparentid=oxobject2category.oxobjectid)";
            $sSqlIfFalse = " {$sArticleTable}.oxid=oxobject2category.oxobjectid ";
            $sVariantsSelectionSnippet = $blVariantsSelectionParameter ? $sSqlIfTrue : $sSqlIfFalse;

            $sQAdd = " from {$sView} as oxobject2category left join {$sArticleTable} on {$sVariantsSelectionSnippet}" .
                     " where oxobject2category.oxcatnid = " . $oDb->quote($sSelId) . " ";
        } elseif ($myConfig->getConfigParam('blBidirectCross')) {
            $sQAdd = " from oxobject2article " .
                     " inner join {$sArticleTable} on ( oxobject2article.oxobjectid = {$sArticleTable}.oxid " .
                     " or oxobject2article.oxarticlenid = {$sArticleTable}.oxid ) " .
                     " where ( oxobject2article.oxarticlenid = " . $oDb->quote($sSelId) .
                     " or oxobject2article.oxobjectid = " . $oDb->quote($sSelId) . " ) " .
                     " and {$sArticleTable}.oxid != " . $oDb->quote($sSelId) . " ";
        } else {
            $sQAdd = " from oxobject2article left join {$sArticleTable} " .
                     "on oxobject2article.oxobjectid={$sArticleTable}.oxid " .
                     " where oxobject2article.oxarticlenid = " . $oDb->quote($sSelId) . " ";
        }

        if ($sSynchSelId && $sSynchSelId != $sSelId) {
            if ($myConfig->getConfigParam('blBidirectCross')) {
                $sSubSelect = "select {$sArticleTable}.oxid from oxobject2article " .
                              "left join {$sArticleTable} on (oxobject2article.oxobjectid={$sArticleTable}.oxid " .
                              "or oxobject2article.oxarticlenid={$sArticleTable}.oxid) " .
                              "where (oxobject2article.oxarticlenid = " . $oDb->quote($sSynchSelId) .
                              " or oxobject2article.oxobjectid = " . $oDb->quote($sSynchSelId) . " )";
            } else {
                $sSubSelect = "select {$sArticleTable}.oxid from oxobject2article " .
                              "left join {$sArticleTable} on oxobject2article.oxobjectid={$sArticleTable}.oxid " .
                              "where oxobject2article.oxarticlenid = " . $oDb->quote($sSynchSelId) . " ";
            }

            $sSubSelect .= " and {$sArticleTable}.oxid IS NOT NULL ";
            $sQAdd .= " and {$sArticleTable}.oxid not in ( $sSubSelect ) ";
        }

        // #1513C/#1826C - skip references, to not existing articles
        $sQAdd .= " and {$sArticleTable}.oxid IS NOT NULL ";

        // skipping self from list
        $sId = ($sSynchSelId) ? $sSynchSelId : $sSelId;
        $sQAdd .= " and {$sArticleTable}.oxid != " . $oDb->quote($sId) . " ";

        return $sQAdd;
    }