In this case,you need to create custom mysql code
which will create mysql like this
Call your collection:
$collections = Mage::getResourceModel('module/namespace_collection');
Call the db resource singleton model
$resource = Mage::getSingleton('core/resource');
Carry connection write connection
$writeConnection = $resource->getConnection('core_write');
Make a custom collection by calling write connection and make a custom subquery:
$subSelect =$writeConnection->select()
->from(
array(' table2' => $collections->getTable('module/namespace')),
array( 'sku', 'MaxDate'=>new Zend_Db_Expr("max(date)"))
)
->group('table2.sku')
Join table
$collections->getSelect()->join(
array(' tm' => new Zend_Db_Expr(sprintf('(%s)',$subSelect->assemble()))),
'main_table.sku = tm.sku and main_table.date = tm.MaxDate,
array()
);
Select your selective columns
$collections->addFieldToSelect('sku')->addFieldToSelect('date');
Code is not tested and put basic of concept
Change your code as below:
$Format = $this->_objectManager->create('ChennaiBox\CustomerAccount\Model\Format');
changed to:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$Format = $objectManager->create('ChennaiBox\CustomerAccount\Model\Format');
You have used $this->_objectManager
but you have not defined it in construct.
Best Answer
1) I Assume you have created Model and Collection file associated with that tables.
2) In a Block PHP file constructor add one argument (Dependency Injection) like below and store it in a class member variable.
3) Prepare a public method in your block to access collection like below.
4) Loop through each of the collection result.
Hope, this will help you.