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
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.
public function __construct(
Context $context,
\Namespace\Modulename\Model\ModelNameFactory $modelNameFactory,
array $data = array()
) {
$this->_modelFactory = $modelFactory;
parent::__construct($context, $data);
}
3) Prepare a public method in your block to access collection like below.
public function getCollection(){
return $this->_modelFactory->create()->getCollection();
}
4) Loop through each of the collection result.
Hope, this will help you.
Best Answer
Render the values from custom table in a custom template, Follow bellow steps.
Create Model and ResourceModel in your custom module for collection to get the table's data.
You can also get data from block using factory method, Calling block from phtml $datacollection = $block->getCollection();
I hope this will useful for you.:)