|
-
Jun 25th, 2002, 04:36 PM
#1
Thread Starter
Stuck in the 80s
Sorting by 2 Fields?
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?
-
Jun 25th, 2002, 05:44 PM
#2
yes you can use
ORDER by comic, number
and it will do pretty much as you say. sort by comic then by the number
-
Jun 25th, 2002, 08:52 PM
#3
Thread Starter
Stuck in the 80s
Yes, I know. Hence my second post. Late as usual, scoutt.
-
Jun 25th, 2002, 09:19 PM
#4
well if you would stop answering your own posts then somebody else might have a chance
-
Jun 26th, 2002, 06:25 AM
#5
Fanatic Member
i think we was just after some confirmation that it would work
-
Jun 26th, 2002, 11:57 AM
#6
Fanatic Member
if you want to get technical and follow "good standards" 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.
Last edited by cpradio; Jun 26th, 2002 at 12:11 PM.
-
Jun 26th, 2002, 12:06 PM
#7
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.
-
Jun 26th, 2002, 12:13 PM
#8
Fanatic Member
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 )
-
Jun 26th, 2002, 12:22 PM
#9
Thread Starter
Stuck in the 80s
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 )
Since when are you caring about standards? 
And why does readability matter when no one else will see my code but me?
-
Jun 26th, 2002, 12:48 PM
#10
Fanatic Member
I dunno!! That is why my position on standards is to "burn them"
-
Jun 26th, 2002, 02:16 PM
#11
oh way to go Matt, see what you did, you got Hobo started on Standards. I think I will disappear *poof*
-
Jun 26th, 2002, 05:49 PM
#12
Thread Starter
Stuck in the 80s
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. 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.
-
Jun 26th, 2002, 05:52 PM
#13
Fanatic Member
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
-
Jun 26th, 2002, 06:03 PM
#14
oh that hurt 
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|