Reputation:
I am a beginner with SQL and I'm following the tutorial at W3 Schools SQL Exercises. I tried to run the following query but I am getting error:
SELECT * FROM Customers LIMIT 5, 5
ERROR:
Syntax error in FROM clause.
Upvotes: 1
Views: 18339
Reputation: 1
I had the same problem. You can use rownum
:
select * from Customers where rownum < 6;
Upvotes: 0
Reputation: 9271
Your problem is that you are using MySql syntax instead of SqlServer syntax. You should use:
SELECT TOP 5 * FROM Customers
Upvotes: 11
Reputation: 57593
You can see that they use ADODB, so you should use TOP clause:
SELECT TOP 5 * FROM Customers
Upvotes: 2
Reputation: 50855
If you're following the example in the link you provided...
We will use the Customers table in the Northwind database:
Northwind is a sample database in MS SQL products. And MS SQL does not have support using LIMIT
queries. So that website is probably using some version of that RDBMS.
Try running:
SELECT TOP 5 * FROM customers;
This gets you the first 5 records in the result set (unordered). It does not skip any records, though, as your LIMIT 5, 5
clause would have.
Upvotes: 3
Reputation:
I suspect you need to use offset
:
select * from Customers limit 5 offset 5;
Not all RDBMSs support the limit m,n
syntax (I believe MySQL does, but PostgreSQL doesn't). Also, you'll probably want to use an order by
clause to help ensure that you get consistent results with your query (because databases, in general, don't care about the order of rows or columns unless you specify):
select * from Customers order by col limit 5 offset 5;
Upvotes: 0