如何在MySQL中搜索表的多个列?

时间:2022-04-01 03:46:05

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

给定一个名为“person”的表(在MySQL数据库/模式中),有点像这样:

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 个解决方案

#1


1  

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

您可以在SQL中使用通配符。这是你想要的?

SELECT * FROM person WHERE code LIKE '%part_of_code%'

#1


1  

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

您可以在SQL中使用通配符。这是你想要的?

SELECT * FROM person WHERE code LIKE '%part_of_code%'