QuestionsSql find data in a group set
mmvikram kumar asked 3 weeks ago

If you are looking some data from collection of groups by id the use FIND IN SET sql function. See below example:-

$andopration =”;

for($f=0;$f<count($categories);$f++){

if($andopration == ”){

$andopration = ‘FIND_IN_SET(‘.$categories[$f].’,categories) > 0 ‘;

}else{

$andopration = ‘(‘.$andopration.’OR FIND_IN_SET(‘.$categories[$f].’,categories) > 0 )’;

}

}

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$resource = $objectManager->create(‘Magento\Framework\App\ResourceConnection’);

$connection = $resource->getConnection(‘core_write’);

$table =  $connection->getTableName(‘uploadfiles_filescollection_items’);

// echo $QURY = ‘SELECT * FROM ‘ . $table .’ WHERE product_ids LIKE “%’.$product->getId().’%”‘;

$QURY = ‘SELECT * FROM ‘ . $table .’ WHERE status=1 AND FIND_IN_SET(‘.$product->getId().’,product_ids) > 0 AND ‘. $andopration;

//die();

$productfiles = $connection->fetchAll($QURY);

Your Answer
Login
Enter email and password to comment or answer
Not the answer you are looking for? Browse other questions tagged or ask your own question.