[英]Search in Full name column with first and last name
I want to achieve is to search for a full name in a database with only a string with his first and last name.我想实现的是在数据库中搜索一个全名,只用一个字符串加上他的名字和姓氏。
in database there is the full name:在数据库中有全名:
Manuel Augusto Vieira Conde Fialho
and I want a sql query that can search this full name only with the first and last name :我想要一个只能用名字和姓氏搜索这个全名的 sql 查询:
Manuel Fialho
I've tried this one:我试过这个:
SELECT name FROM partners WHERE name LIKE 'Manuel Fialho'";
but this does not work for me because I don't have any Manuel Fialho
in the database only a Manuel Augusto Vieira Conde Fialho
and because of that the name im looking for does not show.但这对我不起作用,因为我在数据库中没有任何Manuel Fialho
,只有一个Manuel Augusto Vieira Conde Fialho
,因此我正在寻找的名字没有显示。
thank you谢谢你
您应该添加 %:
SELECT name FROM partners WHERE name LIKE 'Manuel%Fialho';
One method uses wildcards:一种方法使用通配符:
SELECT name
FROM partners
WHERE name LIKE REPLACE('Manuel Fialho', ' ', '%');
SELECT name FROM partners WHERE name LIKE "Manuel%" OR name LIKE "%Fialho";
如果您确定名字的姓氏,那么您也可以使用AND
SELECT name FROM partners WHERE name LIKE "Manuel%" AND name LIKE "%Fialho";
There are 2 possible options to search.有 2 种可能的搜索选项。
Split search string into multiple words and query with that many LIKE
patterns.将搜索字符串拆分为多个单词并使用许多LIKE
模式进行查询。
select name FROM partners WHERE name LIKE '%Manuel%' or name like '%Fialho%'
If you are sure that the sequence of words in the search strings are to match with those in the column value then replace
all spaces with %
symbol and use with LIKE
.如果您确定搜索字符串中的单词序列与列值中的单词序列匹配,则将所有空格replace
为%
符号并与LIKE
使用。
select name FROM partners
WHERE name LIKE concat( '%', replace( 'Manuel Fialho', ' ', '%' ), '%' )
Try Below Query:尝试以下查询:
It works fine..!它工作正常..!
SELECT * FROM `partners` WHERE
`name` LIKE replace( 'Manuel Fialho', ' ', '%' ) OR
`name` LIKE replace('%Manuel Fialho%', ' ', '%' ) OR
`name` LIKE replace('%Manuel Fialho', ' ', '' ) OR
`name` LIKE replace('%Manuel Fialho%', ' ', '' );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.