MYSQL select where column like column1%column2
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);
精彩评论