Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • SQL COUNT,MAX operations in Magento

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 549
    Comment on it

    In magento if we are required to work on SQL and Database with the query to find the max and count of the fields in database then we can perform it as :

    public function countUs(){
            $table = $this->getMainTable();
            $where = $this->_getReadAdapter()->quoteInto("id = ?", 123);
            $select = $this->_getReadAdapter()->select()->from($table)->reset('columns')->columns(new Zend_Db_Expr('count(*)'));
            echo $select.'<br>';
            $select = $this->_getReadAdapter()->select()->from($table)->reset('columns')->columns(new Zend_Db_Expr('max(list_id)'));
            echo $select.'<br>';
        }

    The above query can be seen in sql one as :

    SELECT count(*) FROM `Tablename`
    SELECT max("list_id") FROM `Tablename`

    we can run the complex sql quarries in magento with the help of the query() method, this is done by simply passing the sql query in the method as :

    $sql = ‘…complex sql…’;
    $this->_getReadAdapter()->query($sql);

    we are passing the query to the parameter $sql and then it is passed to query method. This way we can perform the SQL and Database operations in magento.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: