SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jul 2001
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL Help: Backwards auto_increment?

    I was wondering... is there any way for MySQL to count backwards from the highest possible number when assinging ID's to 0?

    Basically, I need it so the last thing submitted is the highest on the list.

    Sorry if that's not too eloquent, I'm pretty new at this.

  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to use ORDER BY in your query:

    SELECT * FROM table ORDER BY column DESC

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  3. #3
    \m/ R.I.P. Dimebag! \m/ JimBolla's Avatar
    Join Date
    Dec 2001
    Location
    erie, pa
    Posts
    1,130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'd suggest doing it the way Sean says, using an ORDER BY column DESC clause on your query. but if for whatever reason you actually need to have the number decrement like you mention, this is possible by setting the Identity Seed and Identity Increment values to something other than one. In your case, you'd set the Identity Seed value to something really really big and set the Identity Increment value to negative one.

    EDIT: After I posted my response I noticed you had said "MySQL" and I'm not sure how similar MySQL is to SQL Server so I don't know what its called in MySQL, but I'd imagine there is some kind of similar functionality.
    Last edited by crowdozer; Apr 1, 2002 at 09:13.

  4. #4
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think you can with MySQL

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  5. #5
    SitePoint Member
    Join Date
    Jul 2001
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by seanf
    You need to use ORDER BY in your query:

    SELECT * FROM table ORDER BY column DESC

    Sean
    Thanks

    Now is there any way for it to return only so many entries?

  6. #6
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT * FROM table ORDER BY column DESC LIMIT 10

    Where 10 is the number of rows you want to return

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature


Bookmarks

Posting Permissions

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