SELECT * FROM products WHERE name LIKE '%a%'

This works fine when case sensitive, but how to search case insensitively?

Thx ahead

有帮助吗?

解决方案

Simple answer:

SELECT * FROM products WHERE lower(name) LIKE '%a%'

其他提示

  SELECT * FROM products WHERE nam LIKE BINARY '%a%'

collate option can also be used and here is how to make it case sensitive from mysql tutorial.

searches for a substring within a larger string you can use CHARINDEX()

If you are using TSQL, you might want to specify a case insensitive collation while doing the search.

e.g.

create table tbl(str varchar(10))

insert into tbl values ('GaP'), ('GAP')

--This will only return 'GaP'
select * from tbl where str collate SQL_Latin1_General_CP1_CS_AS like '%a%'

--This will return both values
select * from tbl where str collate SQL_Latin1_General_CP1_CI_AS like '%a%'
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top