Results 1 to 3 of 3
  1. #1
    vknehra10 is offline Member
    Join Date
    Dec 2016
    Posts
    99
    Rep Power
    0

    Default how to fetch rows between two strings in mysql

    i have some station code list and i want to fetch result between two station codes like ---->>>

    DLI
    DKZ
    SSB
    NNO
    BGZ
    SPZ
    ROK
    KLNK
    BNW

    but i am unable to fetch all codes

    i am applying query like

    select stn_code from code where stn_code BETWEEN 'DLI' AND 'BNW';

    its showing result is "Empty Set" even i have data in my table
    Please Help!!



    Thanks

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,964
    Rep Power
    7

    Default Re: how to fetch rows between two strings in mysql

    "Between" with Strings in SQL is used as >= and <=, so you get all records that have code >= "DLI AND code <= "BNW". Alphabetically, this is not possible. There is NO letter in the alphabet that comes BEFORE 'B' and AFTER 'D'. This explains why there are no records.

    "Between" does not mean between this record and that record. So you need to order your query differently to get all 9 records.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    25

    Default Re: how to fetch rows between two strings in mysql

    What is it about those records, compared to others in that table, that makes them the ones you want?

    At the moment all you have said is "I want this answer", but you haven't said what the question was.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 0
    Last Post: 12-31-2013, 04:36 AM
  2. Replies: 5
    Last Post: 05-03-2013, 01:08 PM
  3. To fetch rows of ms acess database using combobox
    By metagoth in forum AWT / Swing
    Replies: 2
    Last Post: 03-23-2012, 09:54 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •