Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning the number of rows and the details in the same result set?

Status
Not open for further replies.

tbtcust

Programmer
Oct 26, 2004
214
US
I would like to select detailed information from a table. As part of the result set I would also like the total number of rows in the result set. See example below.

Is this possible to do this in a single pass?

Desired result set:
Table_1.Column_1 Table_1.Column_2 Table_1.Column_3 5 Rows Returned
Table_1.Column_1 Table_1.Column_2 Table_1.Column_3 5 Rows Returned
Table_1.Column_1 Table_1.Column_2 Table_1.Column_3 5 Rows Returned
Table_1.Column_1 Table_1.Column_2 Table_1.Column_3 5 Rows Returned
Table_1.Column_1 Table_1.Column_2 Table_1.Column_3 5 Rows Returned


Thanks in advance for any help.
 
My best suggestion (and's not elegant) is:

select t.*, counter.num
from sometable t
, table (select count(*) as num from sometable) as counter

Performance shouldn't be bad as the count part should resolve first as an index only access, but I'd comment my code to explain what I'm doing here!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top