Welcome to the SQLitening support forums!
Started by JoeByrne, December 14, 2008, 03:33:51 am
Quote from: JoeByrne on December 14, 2008, 03:33:51 amIf your table contains more than 20 thousand records, this process may take a few seconds to execute. Is there another way to calculate the number of rows in a table?
SQL$ = "SELECT COUNT(*) As RowCount FROM MyTable;" slSEL(SQL$,1) slGetRow(1) NumberOfRows& = VAL(slFN("RowCount",1)) slCloseSet(1)
QuoteCan this be adapted to count the number of records in a table matching a certain condition?
FUNCTION GetCaseCount(MyFilter AS STRING) AS LONG LOCAL I AS LONG I=0 IF LEN (MyFilter) = 0 THEN slSel "select RowID from master",4 WHILE slGetRow(4) INCR I WEND slCloseSet(4) ELSE slSel "select RowID from master where " & MyFilter,4 WHILE slGetRow(4) INCR I WEND slCloseSet(4) END IF FUNCTION = IEND FUNCTION
slSel "Select 1 from parts" do while slGetRow incr llA loop'============ .14693488 Sec in Local Mode'============ .84143636 Sec in Remote Mode (LocalHost) slSel "Select rowid from parts" do while slGetRow incr llA loop'============ .16349696 Sec'============ 1.10434740 Sec in Remote Mode (LocalHost) slSel "Select count(*) from parts" slGetRow llA = val(slF(1)) slCloseSet'============== .04250660 Sec'============== .04699748 Sec in Remote Mode (LocalHost)
QuoteThe first form returns a count of the number of times that X is not NULL in a group. count(X)The second form (with no argument) returns the total number of rows in the group.count(*)
Quote Does count() have to walk though all the records in a database to find the 30,000 in my particular table?
QuoteI get the same speed with Count() and Count(*)