Question

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

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

Thx ahead

Was it helpful?

Solution

Simple answer:

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

OTHER TIPS

  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%'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top