What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

A positive literal LIMIT should not by itself return more rows than its value. The cause depends on the database and the exact SQL: SQL Server’s TOP (n) WITH TIES can intentionally return extra rows, while SQLite treats a negative evaluated LIMIT as having no upper bound. First inspect the statement the database actually received and the value used for its limit.

Check the SQL engine and the exact statement first

“Limit” can refer to different SQL features. Identify the database engine, then inspect the complete query sent to it—not just the query you expected the application to send. Look for the row-limiting clause, its evaluated value, and any ordering or tie options.

  1. Identify the engine. Confirm whether the query runs on SQL Server, SQLite, MySQL, PostgreSQL, or another database.
  2. Inspect the actual SQL. Check whether the statement uses LIMIT or SQL Server’s TOP, and whether it includes WITH TIES.
  3. Check the evaluated limit. If the limit is an expression or parameter, verify the value that reaches the database—not only the value shown in application code.
  4. Compare row counts at each layer. Check the count returned by the database driver against the count shown by the application. If those differ, investigate fetching or display behavior separately.

SQL Server: check for TOP (n) WITH TIES

SQL Server’s TOP (n) WITH TIES deliberately includes every row tied with the last selected row on the ORDER BY values. As a result, it can return more than n rows; WITH TIES requires an ORDER BY. Microsoft Learn illustrates 31 requested rows producing 33 when three employees named Brown tie at the boundary. That is an example in the documentation, not a typical rate or prediction for other queries. Microsoft Learn explains TOP and WITH TIES.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If the requirement is a hard maximum, remove WITH TIES. Keep an ORDER BY when you need predictable control over which rows are selected.

SQLite: verify the evaluated LIMIT value

SQLite documents that a negative LIMIT means there is no upper bound. If a query unexpectedly returns many rows, inspect the value after any parameter binding or expression evaluation; a negative value may explain why the limit did not cap the result. A NULL or non-convertible limit value produces an error instead. See SQLite’s SELECT documentation.

LIMIT and OFFSET: make row selection deterministic

For MySQL and PostgreSQL, a missing or incomplete ORDER BY can make the selected subset unstable. That does not, on its own, explain a database returning more rows than a positive literal LIMIT. It can explain why different executions or pages contain different rows.

Order by enough columns to distinguish rows, adding a unique key as a tie-breaker when needed. For example, ORDER BY created_at, id can make page membership predictable if id is unique. Adapt the column names to your schema.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Engine-specific checks at a glance

Engine Behavior to check Next step
SQL Server TOP (n) WITH TIES can include rows tied at the boundary. Remove WITH TIES for a hard maximum; retain an order if row choice must be predictable.
SQLite A negative LIMIT means no upper bound. Inspect the evaluated limit expression and its sign.
MySQL Tied rows can appear in any order when the specified ordering columns do not distinguish them. Add ordering columns, including a unique tie-breaker when stable row selection matters.
PostgreSQL Without a predictable ORDER BY, LIMIT/OFFSET can select inconsistent subsets. Specify a deterministic order and add a unique key when needed.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

If the database count is correct but the screen is not

If the database or driver reports no more rows than the limit but the application displays more, the SQL limit may be working correctly. Check whether the application fetches additional batches, combines results, or displays rows from another source. The exact client and its behavior cannot be diagnosed without its name and the relevant query or code.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.