I am trying to view the first 2 records of a table name Customers
which have two columns name Name(varchar)
and Salary(text)
in MySQL server 6.0
Command which I am using is:
SELECT TOP 2 * FROM customers;
But its not working. Can anyone help me.
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. This clause is used when there are thousands of records stored in the database tables.
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. This clause is used when there are thousands of records stored in the database tables.
If you need to use TOP to insert, delete, or modify rows in a meaningful chronological order, use TOP with an ORDER BY clause specified in a subselect statement. See the following Examples section in this article.
For other SQL databases, try the SELECT LIMIT statement. The syntax for the SELECT TOP statement in SQL is: It will return the top number of rows in the result set based on top_value. For example, TOP (10) would return the top 10 rows from the full result set.
I recommend you to write statement like this using LIMIT
SELECT * FROM customers [WHERE conditions] [ORDER BY expression [ASC|DESC]] LIMIT 2 ;
Instead of
SELECT TOP 2 * FROM customers;
It's very simple. Just try this
SELECT * FROM customers LIMIT 2;
You can check the manual also.
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