I have a table, with lots of rows (more than 5,000,000,000), and I want to get the exact number of rows, but as the table has an atrribute called ID like:
ID someAtt someAtt2 someAtt3
-----------------------------------------------
1 32 DOWN 45
...
...
(lots of rows)
...
...
5,000,000,000 25 MOVE 40
What is it the best aproach to get the exact number (here 5,000,000,000)?
using max(ID) or SELECT COUNT(*) FROM table_name
Use
COUNT(*).MAX(ID)will give you an inaccurate count if a row is ever deleted, whileCOUNTwon’t. If you useCOUNT(*)instead of a specific column name, the database server will decide on which column to use to optimize the operation.