Question

Sort of mysql newbie, in Excel I'd do something like 'IsProper' but all I am trying to find here is is the first letter of the second word in the string upper case or not? Or even are ALL words in the field Init Caps or not?

Was it helpful?

Solution

One way to grab all rows where the first letter of the second word is capital

SELECT t.*, SUBSTRING_INDEX(SUBSTRING_INDEX(column1, ' ', 2), ' ', -1) second_word 
  FROM Table1 t
 WHERE CHAR_LENGTH(column1) - CHAR_LENGTH(REPLACE(column1, ' ', '')) > 1
HAVING BINARY LEFT(second_word, 1) = BINARY UPPER(LEFT(second_word, 1))

Given sample data like this

| ID |            COLUMN1 |
---------------------------
|  1 | first second third |
|  2 | first Second third |
|  3 |              first |
|  4 |               NULL |

The output from the query

| ID |            COLUMN1 | SECOND_WORD |
-----------------------------------------
|  2 | first Second third |      Second |

Here is SQLFiddle demo

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top