SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all,

    I have a rather querky but simple problem!
    I want to select all the group names from my table with the first letter begining with the letter 'Z'.

    Sounds simple but I can't seem to get it working. I have managed to do this for all of the other letters of the alphabet (i.e selecting all the group_names begining with 'A', 'B', 'C', 'D' ect...) using the following convention successfully:

    $result = mysql_query( "SELECT group_name, category, region from Groups WHERE group_name >='D' AND group_name < 'E' order by group_name asc")
    or die ("Couldn't execute query");

    This works fine for every letter of the alphabet between A and Y, however I don't know how to bring up all the group names begining with the letter 'Z'!!!

    I tried the following code but it failed to work:

    $result = mysql_query( "SELECT group_name, category, region from Groups WHERE group_name >='Z' AND group_name < 'A' order by group_name asc")
    or die ("Couldn't execute query");

    Please help!!!

    Thanx very much,


    Koncise.

  2. #2
    SitePoint Member
    Join Date
    Apr 2001
    Location
    Newcastle, UK
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how about just using groupname >= 'Z' given that A has a lower value so less than A probably wont work so strip that AND condition out and give it a whirl.

  3. #3
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    WHERE group_name LIKE "Z%"

    This will match all words begining with "Z"

    LIKE is one of the regular expression functions in SQL
    http://www.mysql.com/doc/S/t/String_...functions.html

  4. #4
    SitePoint Member
    Join Date
    Apr 2001
    Location
    Newcastle, UK
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah, so thats the one, I knew LIKE was there, just couldnt remember what the pattern would be thats what I get for answering at university

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2000
    Location
    Location:
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx very much guys....!!!

    I tried the >= 'Z' function and it's working fine now.

    Thanx for the link freakysid .

    K!


Bookmarks

Posting Permissions

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