Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT TOP error

I have this mySQL script:

SELECT TOP 2 * FROM produse ORDER BY `id_produs` DESC

Generates this error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '2 * FROM produse ORDER BY `id_produs` DESC LIMIT 0, 30' at line 1

What is the problem?

like image 273
Calin Mihalache Avatar asked Jul 06 '13 13:07

Calin Mihalache


People also ask

What is select top in SQL?

The SQL SELECT TOP Clause The SELECT TOP clause is used to specify the number of records to return. The SELECT TOP clause is useful on large tables with thousands of records. Returning a large number of records can impact performance.

How do I get top 3 records in SQL?

The SELECT TOP statement in SQL shows the limited number of records or rows from the database table. The TOP clause in the statement specifies how many rows are returned. It shows the top N number of rows from the tables in the output.

How do I select top 10 rows 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.

How do you select top 10 percent in SQL?

Example - Using TOP PERCENT keyword For example: SELECT TOP(10) PERCENT employee_id, last_name, first_name FROM employees WHERE last_name = 'Anderson' ORDER BY employee_id; This SQL Server SELECT TOP example would select the first 10% of the records from the full result set.


2 Answers

there is no TOP in mysql

use LIMIT 2

   SELECT * FROM produse ORDER BY id_produs DESC LIMIT 2
like image 104
echo_Me Avatar answered Sep 18 '22 11:09

echo_Me


Use LIMIT instead:

SELECT * 
FROM   produse
ORDER  BY id_produs DESC
LIMIT  2
like image 44
mishik Avatar answered Sep 22 '22 11:09

mishik