开发者

MYSQL select where column like column1%column2

开发者 https://www.devze.com 2023-03-15 12:53 出处:网络
I have a table with 3 fields, name, firstname and lastname I want to see how many rows in the table have name of the form firstname%lastname

I have a table with 3 fields, name, firstname and lastname

I want to see how many rows in the table have name of the form firstname%lastname

I tried to do

 select * from family_watchdog_offender where name like firstname%lastname\G

bu开发者_如何学Got that returned a syntax error regarding the %lastname portion of the query. Is there some syntax that will allow me to run a query such as this?


SELECT * FROM family_watchdog_offender WHERE name  LIKE CONCAT(firstname, '%', lastname);


Try concat-ing the %:

select * from family_watchdog_offender where name like CONCAT(firstname, '%', lastname)


I don't think you can do that...This may be what you need to do

SELECT * 
FROM family_watchdog_offender 
WHERE name  LIKE CONCAT(firstname, '%') 
 AND name LIKE CONCAT('%', lastname);
0

精彩评论

暂无评论...
验证码 换一张
取 消