Link to home
Start Free TrialLog in
Avatar of DoughBoy
DoughBoy

asked on

Get total number of records but not all records based on an SQL query

Hi,

How do I make an SQL statement retrieve JUST the first 50 rows out of a table but also return the total count of rows that may exist, maybe 400? Should they be two different SQL statments? If so, what would be both statements?

Thanks
DoughBoy
ASKER CERTIFIED SOLUTION
Avatar of sankarbha
sankarbha

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Guy Hengel [angelIII / a3]
I think 2 sql statement should be the best, but run using a stored procedure, where 1 output parameter would be used to return the total number of records...
Avatar of sankarbha
sankarbha

Option 2: (not recommended)

select top 50 a.*,b.totcount
from table a, (
select coun(*) as totcount from table) b


The above query retrieves the top 50 rows and each row have an additional field totcount containing the total no.of rows present in the table
Avatar of DoughBoy

ASKER

thanks!