Number of rows that would have been returned in case of Limit in mysql

Number of rows that would have been returned in case of Limit in mysql

The thing is, you would have sql that have LIMIT appended at the end like

select * from sometable limit 25

but what if you wanted to know how many rows would have been returned if it was not limited?
the trivial approach is

select count(*) from sometable

and then issuing query with limit on it.
This is slower solution.
here is the way to do it in a better way

select sql_calc_found_rows * from sometable limit 25;
select found_rows();

Right after execution the select with sql_calc_found_rows, we would get the ‘would have been’ value on the second query.

See how you would solve these known algorithm problems

Find longest palindrom from sequence of characters

find longest word in the sentence

Kadane’s algorithm in C – Dynamic Programming

Array reversal in Recurrsion

Get maximum occurring character

binary tree problems with solution

testing k complementary pairs algorithm with junit

String Ordered Permutation Algorithm Problem

Java solution for checking anagram strings – tell if phrases are anagrams

Implement Queue Using two Stacks – JavaScript algorithm

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*