FOUND_ROWS() Function for Total Number of Rows Affected in MySQL - MySQL Developer Tutorial

FOUND_ROWS() Function for Total Number of Rows Affected in MySQL


If you want to know how many rows are affected by last statement in MySQL in given sessions, you can use FOUND_ROWS() function.

Let's say we have a table customer with below definition and some sample records.


CREATE TABLE `customer` (
  `idcustomer` int,
  `firstname` varchar(50)  NULL,
  `lastname` varchar(30)  NULL,
  `age` int(11) DEFAULT NULL,
  `phonenumber` char(11) DEFAULT NULL,
  `dob` date DEFAULT NULL,
  `gender` char(1) NOT NULL
) ;

insert into customer(idcustomer,firstname,lastname,age,phonenumber,dob,gender)
values
(1,null,'Ali',39,'505-4141969','1980-01-01','M'),
(2,'Aamir','Naz',39,'505-4141969','1980-01-01','M'),
(3,'Aamir','Shahzad',39,'505-4141900','1980-01-01','M'),
(4,'Aamir1','Shahzad',39,'505-4141900','1980-01-01','M');


Now you can run any statement and then we can run Found_Rows() function to check how many rows are affected.

If we simple run select statement on  customer table.


Select * from customer;


The above query has returned use 4 rows from customer table. We can check the rows affected by above query by using FOUND_ROWS() function.


Select FOUND_ROWS();


use FOUND_ROWS() Function to get rows affected by last statement


1 comment: