Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    Ok this one is easier for me to explain through example so here's the schema of my table:

    Code:
    CREATE TABLE home (
      pic_id int(2) NOT NULL auto_increment,
      pic_name text NOT NULL,
      desc text NOT NULL,
      UNIQUE KEY pic_id (pic_id)
    ) TYPE=MyISAM;
    Query example:
    Code:
    SELECT `pic_id`,`pic_name`,`desc` FROM home WHERE `pic_id`=28 ORDER BY `pic_id` ASC LIMIT 3
    I know this isn't right, it will only return one record, the one with the pic_id of 28. What I want it to do is return 27, 28, and 29. How would I modify my select statement to do this ?
    - Brian

  2.  

  3. #2
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Either by absolute indexing:
    Code:
    SELECT 
        pic_id,
        pic_name,
        desc
    FROM home 
    WHERE pic_id >= 27 
        AMD pic_id < 30
    ORDER BY pic_id ASC;
    Or by relative indexing
    Code:
    SELECT 
        pic_id,
        pic_name,
        desc
    FROM home 
    WHERE pic_id >= 27 
    ORDER BY pic_id ASC
    LIMIT 3;
    The second one is probably what you're looking for. Basically, you can specify the starting identifier and number of items to return and you get everything in between in order.

  4. #3
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    They both work, but the second is easier and more straight forward. Thanks transio, ever higher on the top 10 ladder you climb...
    - Brian


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 11:55 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com