Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: retrieving rows in reverse direction from db

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default retrieving rows in reverse direction from db

    Hi!

    I am implementing pagination using Sql limit in mysql and i want to retrieve records from the last row backwards. There are several thousands records in table

    and i want to retrieve say 500 records at a time to show up in a page.


    If i use "select * from tbl_name order by some_col desc limit 500" it will return

    last 500 records in descending order.

    but i could not find a way to retrieve next block of 500 in reverse direction,

    starting from a point where first block have left up.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: retrieving rows in reverse direction from db

    Depending upon what SQL server you are using, OFFSET might do the trick. If not, post what database you are using, as some of these actions are database specific.

  3. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: retrieving rows in reverse direction from db

    Hi Copeg!

    I am using MySql for database and JDBC for programming purpose

  4. #4
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: retrieving rows in reverse direction from db


  5. #5
    Junior Member
    Join Date
    Dec 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: retrieving rows in reverse direction from db

    when we run "select * from table_name where 'some condition'" then all records from 'select' first goes into main memory of our/client computer then 'where' clause is applied there to return selected rows OR 'where' is directly applied at database server and only rows that satisfy the condition are returned to client.

  6. #6
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: retrieving rows in reverse direction from db

    all records from 'select' first goes into main memory
    It's not quite that simple, nor that brutal. If you're using MySQL and you want to know in detail how a query works, use a MySQL client that allows you to enter SQL statements directly and add "EXPLAIN " to the front of your SQL. MySQL will tell you in detail what it does to produce your results. It's a great first stop for optimising your queries.

    MySQL :: MySQL 5.5 Reference Manual :: 7.8 Understanding the Query Execution Plan

Similar Threads

  1. [SOLVED] Someone point me to the right direction..
    By ineedhelp in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: June 30th, 2011, 10:03 PM
  2. Colouring Rows of a table
    By kurt-hardy in forum Java Theory & Questions
    Replies: 5
    Last Post: March 10th, 2011, 09:49 AM
  3. Homework help, don't understand teach's hint, need some direction
    By crazed8s in forum Java Theory & Questions
    Replies: 2
    Last Post: December 8th, 2010, 04:56 PM
  4. Direction,
    By Time in forum Algorithms & Recursion
    Replies: 2
    Last Post: May 21st, 2010, 05:21 PM
  5. Need a loop for rows and columns
    By Ceasar in forum Loops & Control Statements
    Replies: 8
    Last Post: October 9th, 2009, 05:47 PM