SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member jianyuan's Avatar
    Join Date
    Nov 2003
    Location
    Kuala Lumpur, Malaysia
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how do i select a row before a row?

    how do i select a row before a row?

  2. #2
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT fields FROM table WHERE uniqueid=((SELECT uniqueid FROM table WHERE uniqueid=x) - 1)
    Untested but I can't see why it wouldn't work

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Mist, it wouldn't work before mysql 4.1 since it uses a subquery

    plus, what if there's a gap in id numbers?

    try this:
    Code:
    select id, foo, bar, qux
      from yourtable
     where id < $id
    order 
        by id desc
    limit 1
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hehe good point ^^.

  5. #5
    SitePoint Member jianyuan's Avatar
    Join Date
    Nov 2003
    Location
    Kuala Lumpur, Malaysia
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you very very much . you helped a LOT!


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
  •