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

Categories

0 votes
768 views
in Technique[技术] by (71.8m points)

mysql - TOP and ORDER BY sql error

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

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

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...