« Return to Thread: Problem on creating root password

re: Counting Row Results inside the select

by J.R. Bullington :: Rate this Message:

Reply to Author | View in Thread


                This may sound mundane, but why not use a subselect COUNT?

SELECT COUNT(  
                select concat('Test row ',currentreturnrownum()) as testdata , mytestdata from mytestdatatable;) FROM mytestdatatable;

(I can't test this as I don't have currentreturnrownum()  and cannot find this function in v.5).

You may also want to try the SQL_CALC_FOUND_ROWS  and then FOUND_ROWS()  to get the result.

SELECT SQL_CALC_FOUND_ROWS,  
                 concat('Test row ',currentreturnrownum()) as testdata , mytestdata from mytestdatatable;
SELECT FOUND_ROWS();

J.R.

----------------------------------------

                                From: Lucas.CTR.Heuman@...
Sent: Wednesday, March 28, 2007 10:46 AM
To: mysql@...
Subject: Counting Row Results inside the select

Has anyone found a way to get a result set with the current row return
number in a select statement without using vars?

select concat('Test row ',currentreturnrownum()) as testdata , mytestdata
from mytestdatatable;

+------------------------+-------------------+
|Test row 1             | testdata          |
|Test row 2             | testdata          |
|Test row 3             | testdata          |
|Test row 4             | testdata          |
|Test row 5             | testdata          |
|Test row 6             | testdata          |
|Test row 7             | testdata          |
|Test row 8             | testdata          |
|Test row 9             | testdata          |
+------------------------+-------------------+
(9 rows returned)

Wishing you the best you know you deserve,

______________________
Lucas Heuman
CM Web Developer
SRA International, Inc.
FAA, WJHTC/Bldg 300, 2nd Fl., H33
Atlantic City Int'l Airport, NJ  08405
Phone 609.485.5401


 « Return to Thread: Problem on creating root password