Skip to content

Get random products error

I know that there is a bunch of questions on this topic but no one resolve my problem

//@var MagentoCatalogModelResourceModelProductCollectionFactory $this->_productCollectionFactory
$items = $this->_productCollectionFactory->create();
$items->addAttributeToSelect('*');
$items->getSelect()->orderRand()->limit(10);

this piece of code return this error

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') AS `t`' at line 1, query was: SELECT COUNT(*) FROM () AS `t`