MySQL Forums
Forum List  »  Newbie

Re: Best way to search for a substring?
Posted by: Felix Geerinckx
Date: June 09, 2005 11:34AM

J Pistone wrote:

> I'm trying to search a rather large database for someone's last name. The last names are stored
> as such: LASTNAME, FIRSTNAME
> The input text box allows upper or lower case, and only asks for the person's last name (meaning
> multiple hits would be okay). What's the best syntax to search for the last name by using the
> ',' as a delimiter from the database entry?


SELECT
id
FROM people
WHERE
name LIKE ?

in which you substitute the ? with the content of the textbox followed by a %-character
(e.g. 'Jones%')

Like is not case sensitive, unless you have defined the name column BINARY.
Make sure you have an index on the name column.

(but you really shoulb put lastname and firstname in different columns)

--
felix
Please use BBCode to format your messages in this forum.

Options: ReplyQuote


Subject
Written By
Posted
Re: Best way to search for a substring?
June 09, 2005 11:34AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.