Skip to main content
5 of 6
deleted 5 characters in body
Amit Bera
  • 77.8k
  • 21
  • 127
  • 240

Create Virtual Query

Create ZEND SQL query which is give you artworks_uploaded basic of artist_id,which give an virtual result query with count and artist id.

$ReadAdapter=Mage::getSingleton('core/resource')->getConnection('core_write'); $select = $ReadAdapter()->select() ->from('mage_art_works', array()) ->columns('artist_id', 'artworks_uploaded' => new Zend_Db_Expr('COUNT(*)') )->group('mage_art_works.artist_id'); 

Alias table using above result:

then add the below ZEND SQL to the alias table

$collection->getSelect() ->joinLeft( array('art' => new Zend_Db_Expr($select)), 'main_table.user_id = art.artist_id', array() ); 
Amit Bera
  • 77.8k
  • 21
  • 127
  • 240