Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    Senior Member shoffman3572's Avatar
    Join Date
    Jul 2008
    Location
    Fullerton, CA
    Posts
    137
    Member #
    16990
    Using mySql - is it possible to make a query of a database of peoples names and order them alphabetically - but starting from a specific letter?

    So - I make a query of names which I'd like in order a-z - but I'd like it to start at S - so that the list would order like s,t,u,v,w,z,y,z,a,b,c.... etc

  2.  

  3. #2
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Here's an example listing the first 10 results starting with S (ending with Z)

    SELECT *
    FROM my_table
    WHERE LEFT(name, 1) >= 'S'
    ORDER BY name ASC
    LIMIT 0, 10;

    Page 2 would be LIMIT 10, 10, then Page 3 would be LIMIT 20, 10, and so on.


    Though typically, you only want to show matching items (beginning with the selected letter). For that you would do this:

    SELECT *
    FROM my_table
    WHERE LEFT(name, 1) = 'S'
    ORDER BY name ASC
    LIMIT 0, 10;

  4. #3
    Senior Member shoffman3572's Avatar
    Join Date
    Jul 2008
    Location
    Fullerton, CA
    Posts
    137
    Member #
    16990
    Thanks - that's kind-a-what I was looking for. But that'll only take you from S to Z? No way to have it produce a result that's S through Z back to R ?

  5. #4
    Member Brillig's Avatar
    Join Date
    Mar 2010
    Posts
    32
    Member #
    21509
    Quote Originally Posted by shoffman3572 View Post
    Using mySql - is it possible to make a query of a database of peoples names and order them alphabetically - but starting from a specific letter?

    So - I make a query of names which I'd like in order a-z - but I'd like it to start at S - so that the list would order like s,t,u,v,w,z,y,z,a,b,c.... etc
    Best (and really only) way is with a union.

    SELECT [from your stuff]
    WHERE [names starting with s and greater]
    ORDER BY [names]
    UNION
    SELECT [from your stuff]
    WHERE [names starting with less than s]
    ORDER BY [names]
    Win.ly: A scientific/statistical approach to win prizes online.


Remove Ads

Posting Permissions

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

Search tags for this page

mysql sort on letter

Click on a term to search for related topics.
All times are GMT -6. The time now is 02:05 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com