I am trying to execute the sql query:
select * from table where column like '%value%';
But the data is saved as 'Value' ( V is capital ).
When I execute this query i don't get any rows. How do i make the call such that, it looks for 'value' irrespective of the casing of the characters ?
LIKE performs case-insensitive substring matches if the collation for the expression and pattern is case-insensitive.
Using LOWER( ad UPPER() functions for case sensitive queries In the similar fashion UPPER() and LOWER() functions can be used in the LIKE clause for getting similar records and making the search insensitive in the table or database having collation that shows CS that is case sensitive in its collation.
SQL Server is, by default, case insensitive; however, it is possible to create a case-sensitive SQL Server database and even to make specific table columns case sensitive. The way to determine if a database or database object is to check its "COLLATION" property and look for "CI" or "CS" in the result.
Another way for case-insensitive matching is to use a different “collation”. The default collations used by SQL Server and MySQL do not distinguish between upper and lower case letters—they are case-insensitive by default. The logic of this query is perfectly reasonable but the execution plan is not: DB2.
use LOWER Function in both (column and search word(s)). Doing it so, you assure that the even if in the query is something like %VaLuE%, it wont matter
select qt.* from query_table qt where LOWER(column_name) LIKE LOWER('%vAlUe%');
If you want this column be case insensitive :
ALTER TABLE `schema`.`table` CHANGE COLUMN `column` `column` TEXT CHARACTER SET 'utf8' COLLATE 'utf8_general_ci';
Thus, you don't have to change your query.
And the MySQL engine will process your query quicker than using lower() function or any other tricks.
And I'm not sure that using lower function will be a good solution for index searching performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With