Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    272
    Thanks
    63
    Thanked 1 Time in 1 Post

    simple question (order by)

    How do i make the following:

    Code:
    $get_name = mysql_query("SELECT `id`, `name`, `link`, `value`, `description` from `offers` WHERE `countries` like '%us%' LIMIT 0, 25");
    How do i make that sort by ID from largest number to smallest number? idk where to put the order by
    Last edited by markman641; 08-19-2011 at 09:50 PM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,166
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    ORDER BY is always the *last* thing other than LIMIT. (Well, except for some esoteric options you are not likely to ever need.)

    To sort from low to high, you use ORDER BY fieldname ASC
    To sort from high to low, you use ORDER BY fieldname DESC

    Except that ASC is optional, and is the default if DESC is not coded.

    Here, read the docs:
    http://dev.mysql.com/doc/refman/5.5/en/select.html
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    markman641 (08-26-2011)

  • #3
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    SELECT
    FROM
    WHERE
    GROUP BY
    HAVING
    LIMIT

    as a quick reminder of the syntax order (for most uses)

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,166
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    Ummm...and ORDER BY?

    SELECT
    FROM
    WHERE
    GROUP BY
    HAVING
    ORDER BY
    LIMIT
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    Well yeah i should have included that but you had specifically told the OP where Order By clause went OP.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •