Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an alternative to TOP in MySQL?

Tags:

sql

mysql

I want to know the alternative of the TOP keyword as in MySQL. I have read about TOP in SQL Server.

Is there any alternative to this in MySQL, or any other method in MySQL from which we can get same functionality?

like image 607
Avinash Avatar asked Feb 12 '10 05:02

Avinash


People also ask

What can I use instead of top in MySQL?

The SQL TOP clause is used to fetch a TOP N number or X percent records from a table. Note − All the databases do not support the TOP clause. For example MySQL supports the LIMIT clause to fetch limited number of records while Oracle uses the ROWNUM command to fetch a limited number of records.

What is an alternative for top clause in SQL?

There is an alternative to TOP clause, which is to use ROWCOUNT. Use ROWCOUNT with care, as it can lead you into all sorts of problems if it's not turned off.

How do you top in MySQL?

SQL TOP Syntax The SQL TOP clause is used to limit the number of rows returned. Its basic syntax is: SELECT TOP number | percent column_list FROM table_name ; Here, column_list is a comma separated list of column or field names of a database table (e.g. name, age, country, etc.)

How do I get top 10 in MySQL?

To select first 10 elements from a database using SQL ORDER BY clause with LIMIT 10. Insert some records in the table using insert command. Display all records from the table using select statement. Here is the alternate query to select first 10 elements.


1 Answers

Ordering and limiting the results:

SELECT field1, field2 FROM myTable ORDER BY field1 ASC LIMIT 10 
like image 182
Sampson Avatar answered Sep 22 '22 03:09

Sampson