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
328 views
in Technique[技术] by (71.8m points)

php - How to reverse order output of a MySQL query

I have a basic write to and retrieve SQL database PHP "thing" and I want to have the output in descending order. How do I do that?

For example, the last entry is shown first, then the entry before that, then the entry before that, etc. The first entry ever is last.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Use:

SELECT field_name
FROM table_name
ORDER BY id DESC

By default, MySQL will show results in ascending order. If you want to show them in reverse order, use ORDER BY field_name DESC.

You can use id or date as the field name.


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

...