Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.

Limit results of select statements

Can you limit the number of results returned in a select statement?

Select tablename with somefield eq "something" by someotherfield

but have only 5 keys returned?

Comments

  • Select 5 ........
  • **slaps forehead**
  • edited June 2016
    Unfortunately it doesn't quite achieve the desired effect.

    I want to sort first then limit rather than limit then sort.
    That way I can use a date field and return last five for example.

    In other words I want to limit not randomly select.
  • I just went with a select then loop for n myself.
    If there is another way then I'm all ears.
  • Are you using RLIST, if so , save to a sel;ectlist, then read and grab the top 5
  • *selectlist
  • Mark,

    I'm curious, are you inquiring about this so you can use this in a web report? That is, are you looking to support pagination?
  • Thanks guys.
    Nothing too complex.
    I can and have done it via an rlist and loop.
    I always farm selects off to generic routines (in this case http_resource_services). I was just looking to shortcut the system and avoiding the loop within my calling routine.

    I knew you could restrict the count hence the slapping of my forehead when Barry reminded me but I wasn't sure if it would select, sort, then restrict or if it would do as it does and just select 5 and then sort what it has.

    In the end, I just opted for selecting, loop for n keys and then pass the list of keys to http_resource_services instead of a select statement.

    Does the trick.
  • Mark,

    Just in case it proves useful, you might want to try SELECT.SEEK to manage your pointers and make it easier to paginate your results. This is officially documented in the old Advanced Revelation Developer Series System Subroutines manual, so I am not at liberty to publish the syntax as of yet. I believe I tested this in OI (the object code is definitely there) and it works.
Sign In or Register to comment.