Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to select the last record from a table in MySQL using PHP. I believe I have an SQL error. Here is my SQL code:

SELECT TOP 1 id FROM `table` ORDER BY id DESC

If this is valid and I actually have a PHP error, tell me.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
705 views
Welcome To Ask or Share your Answers For Others

1 Answer

you have an invalid sql syntax. use LIMIT instead

try this:

SELECT id 
FROM table 
ORDER BY id DESC
LIMIT 1

the TOP clause works on MSSQL server.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...