ChrisM ChrisM - 1 month ago 11
SQL Question

How to return only 10 rows via SQL query

I have 1 query that returns over 180k rows. I need to make a slight change, so that it returns only about 10 less.

How do I show only the 10 rows as a result?

I've tried

EXCEPT
but it seems to return a lot more than just the 10.

Answer

You can use LIMIT. This will show first n rows. Example:

SELECT * FROM Orders LIMIT 10

If you are trying to make pagination add OFFSET. It will return 10 rows starting from row 20. Example:

SELECT * FROM Orders LIMIT 10 OFFSET 20