Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search a word by Capital or small letter

Tags:

sql

php

mysql

I have two values in the database like

  1. This is Name
  2. this is a name

I am searching a phrase th by SQL query

SELECT * FROM [TABLE_NAME] WHERE title LIKE '%th%'

then both filed is showing where I want only to show this is a name part. How should I proceed. I have tried preg_merge and other parts but they didn't work. Is there any SQL Query which can distinguish capital and small letter. Or any php method by which I can search exact term. My table format is UTF8. Not Latin General.

like image 709
Soumya Avatar asked Dec 25 '22 12:12

Soumya


1 Answers

SELECT * FROM tableName WHERE title COLLATE latin1_general_cs LIKE '%th%'

Reference

The default character set and collation are latin1 and latin1_swedish_ci, so nonbinary string comparisons are case insensitive by default. This means that if you search with col_name LIKE 'a%', you get all column values that start with A or a. To make this search case sensitive, make sure that one of the operands has a case sensitive or binary collation. For example, if you are comparing a column and a string that both have the latin1 character set, you can use the COLLATE operator to cause either operand to have the latin1_general_cs or latin1_bin collation:

More importantly

If you want a column always to be treated in case-sensitive fashion, declare it with a case sensitive or binary collation. See Section 13.1.10, “CREATE TABLE Syntax”.

like image 88
Hanky Panky Avatar answered Dec 28 '22 07:12

Hanky Panky