How to get count of total records with actual data in single procedure call python?

77 Views Asked by At

I made a procedure that gets all the customers from my database table.I can even pass search parameter like search on customer name or phone no. Now I want the count of total records found. Because I am using limit clause so I can not use FOUND_ROWS(). So I call same procedure two times one for actual data with limit clause and search parameter and second time to get count of total records matching with search parameter without limit clause ? Any optimized solution ?

1

There are 1 best solutions below

0
On

I've done something similar to this before. It might not be faster, but you can do it in one query like this: (EMAIL is the table name,MAIL_NO is the primary key column)

SELECT *,(Select count(MAIL_NO) from EMAIL) as num  FROM `EMAIL` 

This is the resulting table:

MAIL_NO BIZ_ID  FROM_ADD    TO_ADD  EMAIL_SUBJECT   MAIL_STATUS UPDATED_DATE    num
1   1   2   3   test    A   NULL    3
3   1   2   1   test2   A   NULL    3
2   1   2   3   test 2  A   NULL    3