I have an MySQL table with 25000 rows.
This is an imported CSV file so I want to look at the last ten rows to make sure it imported everything.
However, since there is no ID column, I can't say:
SELECT * FROM big_table ORDER BY id DESC
What SQL statement would show me the last 10 rows of this table?
The structure of the table is simply this:
columns are: A, B, C, D, ..., AA, AB, AC, ... (like Excel)
all fields are of type TEXT
If you want to retrieve last 10 records from sql use LIMIT. Suppose the data base contains 20 records.Use the below query
where 10,20 is the offset value.Where 10 represent starting limit and 20 is the ending limit.
i.e 20 -10=10 records
Select from the table, use the ORDER BY __ DESC to sort in reverse order, then limit your results to 10.
That can be done using the limit function, this might not seem new but i have added something.The code should go:
for the above case assume that you have 110 rows from the table and you want to select the last ten, 100 is the row you want to start to print(if you are to print), and ten shows how many rows you want to pick from the table. For a more precised way you can start by selecting all the rows you want to print out and then you grab the last row id if you have an id column(i recommend you put one) then subtract ten from the last id number and that will be where you want to start, this will make your program to function autonomously and for any number of rows, but if you write the value directly i think you will have to change the code every time data is inserted into your table.I think this helps.Pax et Bonum.
If you're doing a
LOAD DATA INFILE 'myfile.csv'
operation, the easiest way to see if all the lines went in is to checkshow warnings();
If you load the data into an empty or temporary table, you can also check the number of rows that it has after the insert.If you have not tried the following command
I see it's working when I execute the command
in the Try it yourself command window of https://www.w3schools.com/sql/sql_func_last.asp