SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Selecting Users with Last Names That Begin With a Range of Letters (e.g., A-F)

    My goal is to select users with last names that begin with a range of letters (e.g., A-F).

    MySQL version: 5.1.54-community

    I am executing the SQL within PHP MyAdmin 3.3.8.1

    This will successfully return records (last names beginning with 'B'):

    Code:
    SELECT * FROM `users` WHERE `last_name` LIKE 'B%'
    However, this query is SUPPOSED to return records of users with last names that begin with letters A-F:

    Code:
    SELECT * FROM `users` WHERE `last_name` LIKE '[A-F]%'
    Here is the table I am querying:

    Code:
    CREATE TABLE IF NOT EXISTS `users` (
      `userid` varchar(25) NOT NULL DEFAULT '',
      `first_name` varchar(50) NOT NULL DEFAULT '',
      `last_name` varchar(50) NOT NULL DEFAULT '',
      `email` varchar(100) NOT NULL DEFAULT '',
      `work_address1` varchar(100) NOT NULL DEFAULT '',
      `work_address2` varchar(100) DEFAULT '',
      `work_city` varchar(100) NOT NULL DEFAULT '',
      `work_state` char(2) NOT NULL DEFAULT '',
      `work_zip` varchar(10) NOT NULL DEFAULT '',
      `home_address1` varchar(100) DEFAULT '',
      `home_address2` varchar(100) DEFAULT '',
      `home_city` varchar(100) DEFAULT '',
      `home_state` char(2) DEFAULT '',
      `home_zip` varchar(10) DEFAULT '',
      `work_phone` varchar(20) NOT NULL DEFAULT '',
      `home_phone` varchar(20) DEFAULT '',
      `mobile_phone` varchar(20) DEFAULT '',
      `fax` varchar(20) DEFAULT '',
      `primary_phone` varchar(100) NOT NULL DEFAULT '',
      `manager` varchar(100) DEFAULT '',
      `connection_type` varchar(100) DEFAULT '',
      `organization` varchar(255) DEFAULT NULL,
      `group_id` int(10) unsigned DEFAULT '1',
      `must_update` int(2) unsigned NOT NULL DEFAULT '0',
      `must_change_pw` int(1) unsigned NOT NULL DEFAULT '0',
      `last_updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
      `use_cached_login` int(1) unsigned NOT NULL DEFAULT '0',
      `active` int(2) unsigned NOT NULL DEFAULT '0',
      PRIMARY KEY (`userid`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

    Any help is greatly appreciated.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,216
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    here ya go, surnames A through F...
    Code:
    WHERE last_name >= 'A'
      AND last_name  < 'G'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2011
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    here ya go, surnames A through F...
    Code:
    WHERE last_name >= 'A'
      AND last_name  < 'G'
    Thx, that works! I appreciate the post.


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
  •