Results 1 to 14 of 14

Thread: Sorting by 2 Fields?

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    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?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    scoutt
    Guest
    yes you can use

    ORDER by comic, number

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

  3. #3

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Yes, I know. Hence my second post. Late as usual, scoutt.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  4. #4
    scoutt
    Guest
    well if you would stop answering your own posts then somebody else might have a chance

  5. #5
    Fanatic Member ubunreal69's Avatar
    Join Date
    Apr 2001
    Location
    Morayfield, Australia
    Posts
    609
    i think we was just after some confirmation that it would work

  6. #6
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    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.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  7. #7
    scoutt
    Guest
    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.

  8. #8
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    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 )
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  9. #9

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    I dunno!! That is why my position on standards is to "burn them"
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  11. #11
    scoutt
    Guest
    oh way to go Matt, see what you did, you got Hobo started on Standards. I think I will disappear *poof*

  12. #12

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    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.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  13. #13
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    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
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  14. #14
    scoutt
    Guest
    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
  •  



Click Here to Expand Forum to Full Width