SELECT TOP in MySQL
Question: Is there a way to emulate the behavior of SELECT TOP [Integer] … in MySQL?
Answer: Yes there is…you have to make use of the LIMIT clause.
Example:
The query…
SELECT TOP 5 * FROM movies;
Output:
| titleID | title | url |
|---|---|---|
| 0012349 | The Kid | http://www.imdb.com/title/tt0012349/ |
| 0015864 | The Gold Rush | http://www.imdb.com/title/tt0015864/ |
| 0017136 | Metropolis | http://www.imdb.com/title/tt0017136/ |
| 0017925 | The General | http://www.imdb.com/title/tt0017925/ |
| 0018455 | Sunrise: A Song of Two Humans | http://www.imdb.com/title/tt0018455/ |
…will look like this in MySQL…
SELECT * FROM movies LIMIT 5;
Output:
| titleID | title | url |
|---|---|---|
| 0012349 | The Kid | http://www.imdb.com/title/tt0012349/ |
| 0015864 | The Gold Rush | http://www.imdb.com/title/tt0015864/ |
| 0017136 | Metropolis | http://www.imdb.com/title/tt0017136/ |
| 0017925 | The General | http://www.imdb.com/title/tt0017925/ |
| 0018455 | Sunrise: A Song of Two Humans | http://www.imdb.com/title/tt0018455/ |
You can find more information about selections with LIMIT here.
Hope this helps…
