Your error isn't a Python one, it's a question of SQL syntax which differs between Oracle Database (which Connor was referring to), and MySQL / MariaDB.
As you can see from the documentation [1] MySQL does not support the
fetch first 10 rows clause, but instead has the
limit 10 rows clause instead. You should be able to adjust Connor's query by substituting as above to get your desired result.
On a broader level, there's another thread on
AskTom discussing the topic of how to determine the meaning of
first and
last more extensively for Oracle Database [2] which uses a
SQL subseslect to get the correct result, but the conceptual reasoning applies to SQL in general so it's a worthwhile read if you're interested.
It's critical to understand the measure against which you're creating the query, and the supposed reason behind the need for it, in real-world scenarios. See the later comments at [2] for March 5th 2021 in which a reader explains their reasoning as needing to populate an additional table at insert time, with the child record in the details table linked back to a parent table. The solution in this case was
insert into... returning... and is a great example of proper problem analysis.
Using the same assumptions as Connor, having a column called DATE_CREATED, here's another approach you might try which may be easier to understand; this uses
Common Table Expressions and is probably overkill in this situation:
WITH FirstTen as ( SELECT * FROM zipodes_one.zipcodes_one ORDER BY DATE_CREATED ASC )
SELECT * FROM FirstTen WHERE ROWNUM <=10;
WITH LastTen as ( SELECT * FROM zipodes_one.zipcodes_one ORDER BY DATE_CREATED DESC )
SELECT * FROM LastTen WHERE ROWNUM <=10;
WITH FirstZip as ( SELECT * FROM zipodes_one.zipcodes_one ORDER BY DATE_CREATED ASC )
SELECT * FROM FirstZip WHERE ROWNUM =1;
WITH LastZip as ( SELECT * FROM zipodes_one.zipcodes_one ORDER BY DATE_CREATED ASC )
SELECT * FROM LastZip WHERE ROWNUM =1;
The
Common Table Expression or
CTE is documented for MySQL at [3], linked below.
Small tip: when asking a question and it asks for version, it's referring to the database verison you're working with.
Hope this helps - good luck :-)
[1]
https://docs.oracle.com/cd/E17952_01/mysql-8.0-en/select.html [2]
https://asktom.oracle.com/pls/apex/asktom.search?tag=fetching-last-record-from-a-table [3]
https://docs.oracle.com/cd/E17952_01/mysql-8.0-en/with.html