PDA

Click to See Complete Forum and Search --> : Sorting by 2 Fields?


The Hobo
Jun 25th, 2002, 04:36 PM
I'm creating a database to store comics in. Includes name, number, price, condition, etc.

When I list the comics is there a way I can specify in the SQL statement to sort by name then number? So that it sorts first by comic names so that they're alphabetical. Then it sorts by comic number?

scoutt
Jun 25th, 2002, 05:44 PM
yes you can use

ORDER by comic, number

and it will do pretty much as you say. sort by comic then by the number

The Hobo
Jun 25th, 2002, 08:52 PM
Yes, I know. Hence my second post. Late as usual, scoutt. :p

scoutt
Jun 25th, 2002, 09:19 PM
well if you would stop answering your own posts then somebody else might have a chance :p

ubunreal69
Jun 26th, 2002, 06:25 AM
i think we was just after some confirmation that it would work :p

cpradio
Jun 26th, 2002, 11:57 AM
if you want to get technical and follow "good standards" :p the following is a more precise way:

Common Mistakes:
ORDER BY comic and number // , instead of and

ORDER BY comic, number DESC // orders comic ascendingly and number descendingly, and not both as descendingly

ORDER BY comic ASC, number DESC // orders comic ascendingly and number descendingly (no real mistake can be made here)

ASC (Ascending) or DESC (Descending) should follow your field even though MySQL will tend to use ASC as its default.

scoutt
Jun 26th, 2002, 12:06 PM
actually Mysql does it both ways

mysql> SELECT ... FROM tbl_name ORDER BY key_part1,key_part2,... ;
mysql> SELECT ... FROM tbl_name ORDER BY key_part1 DESC,key_part2 DESC,... ;

so I don't think it really a standard, it's just that it will work both ways.

cpradio
Jun 26th, 2002, 12:13 PM
Well, the reason I say "good standards" is because standards normally tend to go with readability, and by placing ASC or DESC after each column it establishes a better chance of someone else being able to understand it (though using comments with each important line would be just as helpful :cool: )

The Hobo
Jun 26th, 2002, 12:22 PM
Originally posted by cpradio
Well, the reason I say "good standards" is because standards normally tend to go with readability, and by placing ASC or DESC after each column it establishes a better chance of someone else being able to understand it (though using comments with each important line would be just as helpful :cool: )

Since when are you caring about standards? :D

And why does readability matter when no one else will see my code but me?

cpradio
Jun 26th, 2002, 12:48 PM
I dunno!! That is why my position on standards is to "burn them"

scoutt
Jun 26th, 2002, 02:16 PM
oh way to go Matt, see what you did, you got Hobo started on Standards. I think I will disappear *poof*

The Hobo
Jun 26th, 2002, 05:49 PM
Originally posted by scoutt
oh way to go Matt, see what you did, you got Hobo started on Standards. I think I will disappear *poof*

Shut up, Scoutt. :p He's a standards freak, I was just asking why he was abiding them suddenly.

And I agree with standards that help my coding. It's just the ones that tell me how many spaces I need before a "(" that I laugh at.

cpradio
Jun 26th, 2002, 05:52 PM
I have only been picky over standards the past few days because I have been validating my CSS and XHTML code. As far as PHP goes, I use my own technique as it tends to work well :p

scoutt
Jun 26th, 2002, 06:03 PM
oh that hurt :p

well I agree with the both of you. I think the spaces before the ( and after the ) is really stupid as well. and I really doubt they will get it to a be real standard.