[SOLVED] Too many records in a TZquery. Problem with Record Count lazarus / 16-Databases ---------------------------------------------------------------------- donnie · 2016-05-25 07:52 Hi there, I've got a TZQuery connected with a TDatasource which is connected to my TRXDBGrid(same as TDBGrid with many functions). My query brings from my database about 300.000 records and as they are enough when I open my query to bring the records to my DBGrid I have changed the FetchRow to 1000 in order not to wait too long. I have also added a button to my form with the title Total Count which brings me the number of Records in my DBgrid. In that button (SBRecordsCount) when I press it, the caption changes and shows the record count. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SBRecordsCount.Caption:= 'Total: ' + inttostr(MyQuery.RecordCount); With the above code the recordcount is 1000 which is the number of the fetched rows something which I expected. So I changed it to Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    MyQuery.last;   MyQuery.first;   SBRecordsCount.Caption:= 'Total: ' + inttostr(MyQuery.RecordCount); The problem is that now that is too slow and sometimes it takes too much time to bring the number (more that 5 minutes) which is not logical. Is there any other way to load the record count somewhere else (memory) in order to take that number quicker? Thank you, in advance. ---------------------------------------------------------------------- balazsszekely · 2016-05-25 08:16 Quote@dony The problem is that now that is too slow and sometimes it takes too much time to bring the numberAdd another TSQLQuery, with the following sql: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i select count(id) as recordcount from TableNameWhere id is the primary key. Any other field will do it, but preferably choose an indexed one. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i SQLQuery1.Open;SBRecordsCount.Caption:= 'Total: ' + SQLQuery1.FieldByName('recordcount').AsString; SQLQuery1.Close ---------------------------------------------------------------------- donnie · 2016-05-25 08:40 Excellent less than one second. Thank you very much.