#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0

    Yet another query problem.


    Hi all,

    So I'm trying to write a very simple query, but this is the first time I'm using Firebird, and I'm kind of stuck with this problem. There are probably very simple errors in my query, too simple to notice for a fresh Firebird user.

    The problem concerns the following table:

    String_ID (int) | String (varchar)
    4532 alfa
    7890 zeta
    55324 beta
    12345 gamma
    323424 omega
    ...

    I need to sort this table by String and return records that after sorting happen to be immediately after one particular given record.

    And there has to be only a few returned records (or even one record) at a time. What do I do in order to optimize this query for subsequent uses, ie. if I want to get another few records after the records I got before?

    For the above table and the given record "beta":

    The table after sorting by String:

    String_ID (int) | String (varchar)
    4532 alfa
    55324 beta
    12345 gamma
    323424 omega
    7890 zeta

    The desired output would be:
    12345 gamma
    323424 omega

    Thanks for your help.
    GDB
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0
    Now I figured out that my problem translates to a very simple one:
    Given one string I need to get next string in alphabetical order. Anyone knows how to do that in firebird?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2011
    Posts
    3
    Rep Power
    0
    The answer is:

    select * from Table where String>'beta' order by String rows 1 to 2

    Again, google is your friend, although sometimes not very cooperative...

IMN logo majestic logo threadwatch logo seochat tools logo