From the course: SQL: Data Reporting and Analysis

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Make your queries faster

Make your queries faster - SQL Tutorial

From the course: SQL: Data Reporting and Analysis

Make your queries faster

- [Instructor] If we click on the payment table, you can see that there are 16,000 odd results. And this query took 0.0009 seconds. Now we're going to limit our query to 25 rows, and do that by limit 25 and click go. Now you can see that the query took a little bit less time, 0.007 seconds to run. But when we're dealing with millions of rows, this sort of thing can make a substantial difference. The limit keyword works in MySQL and PostgreSQL, but unfortunately the keywords differ in different versions. So for Microsoft, the keyword is top, and you use it like this. You'd say select top 25, field name, whatever that field name may be from the payment table. And obviously you don't need that bit. And for Oracle, it would be select, I'll show you. Star from the table. And then it's used as a filter where ROWNUM is less than or equal to 25. And ROWNUM isn't a field, it's Oracle's own way of counting the rows in the database.…

Contents