yiwei
yiwei

Reputation: 4190

set variable to count of rows in mysql

This isn't a complete question, but I was just wondering if there was a better or more elegant way to set a variable to the count of the number of rows from a mysql select statement. Currently, what I have is:

SET @myCount = 
(SELECT COUNT(*) 
FROM table1
WHERE aCondition = TRUE);

Upvotes: 0

Views: 299

Answers (1)

Raphaël Althaus
Raphaël Althaus

Reputation: 60493

you can use a select... into (donnow if you find this more "elegant")

select count(*) into @myCount
from table1
where aCondiction = TRUE;

Upvotes: 1

Related Questions