MySQL for selecting for a Title begining with a certain letter?

Discussion in 'PHP' started by nickharper, Oct 14, 2007.

  1. #1
    Hi,

    I am trying to work out a query how I can select records just by the letter that the title starts with but I can't seem to figure it out.

    I want to be able to basically list every record where the title begins with A.

    Thanks
     
    nickharper, Oct 14, 2007 IP
  2. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #2
    Try "LIKE a%".

    But without a key, this could be a table walk and not be very efficient. Make sure you use an index.

    In one of my apps, I checked the title before storing the title. I grabbed the first letter, ignoring "A" and "The" as beginning words, and created an index field for what letter that record should be associated with.

    Then I query the index for all titles beginning with whatever letter. Much more efficient.
     
    noppid, Oct 14, 2007 IP