How to find the last line number or last line ID? Suppose I have such a table:
ID NAME E-mail PASS
one
2
3
four
So, how can I tell the script the last line number or the last line ID?
|
2 answers
If I understood correctly, then:
1) Last line ID:
select max(id) from table
2) Last line number = total number of lines:
select count(*) from table
I note that in real work - option 2 is very rarely needed (when work goes with strings, not sets)
- A "max (id)" Write as MAX (id) or max (id)? - igolka97
- oneno difference ... Some (including I) write with a large one, so that I can immediately see where the names of the fields / tables, and where the sql constructions, ie, SELECT MAX (id) FROM table SELECT COUNT (*) FROM table - timka_s
|
^ The above nonsense
SELECT * FROM `tbl` ORDER BY `id` DESC LIMIT 1
In this case, that would not be stored in the fields, stretch the last line.
- all the rules above - igolka97
- one@Elime, be careful with the statements, you are in a decent place ... However, your answer does not correspond to the question ... - timka_s
- What is he not up to? - Elime
- If you write as you propose (I usually write it myself), then you should write: SELECT id FROM
tbl
ORDER BYid
DESC LIMIT 1 You select all fields of the last row of the table. - Zowie - Question: How to find out the last line number or the last line ID You answer the question: How to get the last line when sorting by ID - timka_s
|