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.
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.
Your problem is that you are using MySql syntax instead of SqlServer syntax. You should use:
SELECT TOP 5 * FROM Customers
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.
ORDER BY anyway and so ORDER is undefined you might as well just imagine that it has skipped 5 arbitrary records as the only time it will make a difference is if the table has between 5-10 rows.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;