PDA

View Full Version : opposite of DESC


The Wizzard
12-20-2002, 12:56 AM
Hey...

When I use

"SELECT * FROM list ORDER BY ID DESC"

It lists the things from my database backwards, the ID field would look like..

1
2
3
4
5

And when I use that line of code above, it comes out like

5
4
3
2
1

So whats the opposite of DESC??

THanks!

glenngv
12-20-2002, 01:02 AM
ASC

if not specified, ASC (Ascending) is the default.

The Wizzard
12-20-2002, 01:11 AM
Thanks!

whammy
12-20-2002, 01:27 AM
Yeah if you don't specify DESC, SQL will by default order ASC.

Of course, keep in mind if you need to order by a particular field, you need to say:

ORDER BY fieldname [ASC is assumed here unless you specify otherwise]

You can also use multiple fields in your ORDER BY clause (as long as those fields were selected in your SQL Statement) comma delimited - play around with it!

;)

Mhtml
12-20-2002, 03:34 AM
Example: ordering by a field..Ascending

SELECT * FROM Posts ORDER BY DateCreated ASC

Example: odering by a field..Descending

SELECT * FROM Posts ORDER BY DateCreated DESC


For anyone who ends up reading this and doesn't get it ;)

raf
12-20-2002, 07:47 AM
I tryed it and it didn't work !!
It say: "table could not be found". What am I doing wrong !?!?!?;)

seriously, you can also order on more then one variable. (first one gets priority etc)
here's the complete syntax.

SELECT fieldlist
FROM table
WHERE selectcriteria
[ORDER BY field1 [ASC | DESC ][, field2 [ASC | DESC ]][, ...]]]

Mhtml
12-20-2002, 07:56 AM
LOL:)

whammy
12-21-2002, 01:55 AM
Didn't I already say that? ;)