how to Search multiple columns of a table in MySQL?
-
03-07-2019 - |
Question
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!
Solution
You can use wild cards in SQL. Is this what you are looking for?
SELECT * FROM person WHERE code LIKE '%part_of_code%'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow