Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to fire select query which is as follows

SET @a = 0;
SELECT @a:=@a+1 as count FROM admin_user;

How I can add SET variable in SQL query in magento.
Thanks in Advance.

share|improve this question
up vote 4 down vote accepted

First you have run this Query

/* Get the  core resource model */
$resource = Mage::getSingleton('core/resource');

/*  Retrieve the read connection */
 $readConnection = $resource->getConnection('core_read');
 $query = 'SELECT @cnt:= 0 ;';
 $results = $readConnection->fetchAll($query);

Then Your Query i:e

SELECT @a:=@a+1 as count FROM admin_user;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.