Skip to main content
Participating Frequently
May 19, 2006
Question

How can I show all results from my DB in reverse row order?

  • May 19, 2006
  • 5 replies
  • 419 views
So if I have three rows in the database, called John, Steve, Tom, if you usually display all results from a database to a web page, you will get just this order. I have found order by SQL syntax, but this orders numerically or alphabetically. How can I order the table contents backwards so that the rows wil read Tom, Steve, John?

Thanks,
Mark
This topic has been closed for replies.

5 replies

Inspiring
May 19, 2006
On 19 May 2006 in macromedia.dreamweaver.appdev, Lionstone wrote:

> First and Last were names Joe chose for the columns holding the
> first and last name. Since you mentioned first names as your
> values, he used First (his first name column) to order by.

Good point, and "First" and "Last" may well be keywords, which will drive
a DBMS nuts. I should have been more careful in picking them.

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/email.php
Inspiring
May 19, 2006
"15266" <webforumsuser@macromedia.com> wrote in message
news:e4kbs9$poi$1@forums.macromedia.com...
>I think it should be something like:
>
> SQLQuery = "SELECT * FROM HCT122 ORDER BY ?firstvalue? DESC"
>
> but how I define what is the first or last row name or number, without
> referring to its name?

You misunderstood Joe's answer. You don't have to know any of that. First
and Last were names Joe chose for the columns holding the first and last
name. Since you mentioned first names as your values, he used First (his
first name column) to order by.

In order to sort something, you have to know what it is you're sorting.
Since you're unwisely using SELECT *, I'll make up column names for you.

SELECT AB, BC, CD, DE
FROM HCT122
ORDER BY AB DESC

Now all my records come back in reverse order by column AB.


Inspiring
May 19, 2006
Add a date/time column to your table - have it populate itself when an
insert occurs (default value) and sort by that column DESC.
HTH
Rob
http://robgt.com/ [Tutorials and Extensions]
Firebox stuff: http://robgt.com/firebox
Skype stuff: http://robgt.com/skype
Dell stuff: http://robgt.com/dell
SatNav stuff: http://robgt.com/satnav



15266Author
Participating Frequently
May 19, 2006
I think it should be something like:

SQLQuery = "SELECT * FROM HCT122 ORDER BY ?firstvalue? DESC"

but how I define what is the first or last row name or number, without referring to its name?
Inspiring
May 19, 2006
On 19 May 2006 in macromedia.dreamweaver.appdev, 15266 wrote:

> So if I have three rows in the database, called John, Steve, Tom, if
> you usually display all results from a database to a web page, you
> will get just this order. I have found order by SQL syntax, but this
> orders numerically or alphabetically. How can I order the table
> contents backwards so that the rows wil read Tom, Steve, John?

SELECT First, Last, Whatever FROM mytable ORDER BY First DESC

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/email.php
15266Author
Participating Frequently
May 19, 2006
Thanks for the idea, but unfortunately I cannot know what the name of the last row will be, as it will change constantly because users insert records into the comments database regularly, so they will not be static names. ORDER BY and DESC or ASC will be the way to go though I think, I'm just not sure exactly how!