Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Mysql have an equivalent to @@ROWCOUNT like in mssql?

How can I get row count values in MySQL as @@ROWCOUNT does in mssql?

like image 770
abs Avatar asked Feb 09 '10 13:02

abs


People also ask

How can I get Rowcount in MySQL?

To get the count of all the records in MySQL tables, we can use TABLE_ROWS with aggregate function SUM. The syntax is as follows. mysql> SELECT SUM(TABLE_ROWS) ->FROM INFORMATION_SCHEMA.

What is Rownum in MySQL?

Row_NUMBER() included from MySQL version 8.0. It is a type of window function. This can be used to assign a sequence number for rows. To understand, create a table with the help of CREATE pcommand −

What is the use of @@ rowcount in SQL Server?

SQL Server @@ROWCOUNT is a system variable that is used to return the number of rows that are affected by the last executed statement in the batch.

How do I get Rowcount in SQL?

The SQL COUNT() function returns the number of rows in a table satisfying the criteria specified in the WHERE clause. It sets the number of rows or non NULL column values. COUNT() returns 0 if there were no matching rows. The above syntax is the general SQL 2003 ANSI standard syntax.


2 Answers

For SELECTs you can use the FOUND_ROWS construct (documented here):

SELECT SQL_CALC_FOUND_ROWS something FROM your_table WHERE whatever; SELECT FOUND_ROWS( ) ; 

which will return the number of rows in the last SELECT query (or if the first query has a LIMIT clause, it returns the number of rows there would've been without the LIMIT).

For UPDATE/DELETE/INSERT, it's the ROW_COUNT construct

INSERT INTO your_table VALUES (1,2,3); SELECT ROW_COUNT(); 

which will return the number of affected rows.

like image 108
AndiDog Avatar answered Sep 19 '22 19:09

AndiDog


mysql> SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name      -> WHERE id > 100 LIMIT 10;  mysql> SELECT FOUND_ROWS(); 

Read more about this here

like image 38
Lazarus Avatar answered Sep 19 '22 19:09

Lazarus