views:

621

answers:

1

Given a table named "person" (in a MySQL database/schema), kind of like this one:

code varchar(25)  
lastname varchar(25)  
firstname varchar(25)

I'm trying to make a stored function to receive "code" or a part of "code" (which of course, is the code that identifies that person) and return a 'list' of suggestions of persons that have a similar code.

What I'm not sure is how to search like in an auto complete kind of way, returning all possible results (or just five); and also how to return this "list" of persons from the stored procedure.

Any idea how I could do this?, Thanks!

+1  A: 

You can use wild cards in SQL. Is this what you are looking for?

SELECT * FROM person WHERE code LIKE '%part_of_code%'
jakber
yes, but how do I return the "list" of possible codes from the stored function?
ramayac
In MySQL you can actually just do the select without using a cursor or variable and it will be returned to the client. See http://dev.mysql.com/doc/refman/5.0/en/stored-routines-syntax.html
jakber