按资本或小写字母搜索单词

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.

it will work for you, try this query

SELECT * FROM table_name WHERE BINARY title LIKE '%th%'
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”.

This is a way to select words beginning with an lowercase.

This query check if the first character is an lowercase by the function LOWER() and if the following character is a lowercase with the same function LOWER().

If you want to assure that all the following characters are lowercase you can use LOWER(SUBSTRING(word FROM 2))

SELECT title
FROM [TABLE_NAME] 
WHERE (SUBSTRING(title, 1, 1) COLLATE latin1_bin) = LOWER(SUBSTRING(title, 1, 1)) 
AND (SUBSTRING(title, 2, 1) COLLATE latin1_bin ) = LOWER(SUBSTRING(title, 2, 1))

$keywords = '%'.strtolower($_GET['q']). '%';

$sql= mysql_query("SELECT * FROM items WHERE LOWER(item_code) LIKE '$keywords' ");