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?
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.
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.
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.
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.
there is no TOP in mysql
use LIMIT 2
SELECT * FROM produse ORDER BY id_produs DESC LIMIT 2
Use LIMIT
instead:
SELECT *
FROM produse
ORDER BY id_produs DESC
LIMIT 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With