How can I count the number of rows returned by MySQL Query?

Is there an easier way to do this, besides loading data into a DataTable and using Rows.Count or using MySqlDataReader and iterating over all the given lines?

+6
source share
4 answers

if you cannot easily change the request

 SELECT COUNT(*) FROM (<your complete query here>) 
+6
source

You can execute a query, for example:

 SELECT COUNT(*) FROM MyTable; 
+1
source

You can use the MySQL information function FOUND_ROWS . Just run it right after the SELECT query. Like this:

 SELECT FOUND_ROWS() 
+1
source

Exec a

 select count(*) from MyTable WHERE <clause> 

and get the result using ExecuteScalar ()

0
source

Source: https://habr.com/ru/post/888339/


All Articles