MySQL select words beginning with uppercase
This is a way to select words beginning with an uppercase. This query check if the first character is an uppercase by the function UPPER() and if the following character is a lowercase with the function LOWER(). If you want to assure that all the following characters are lowercase you can use LOWER(SUBSTRING(word FROM 2))
SELECT word, SUBSTRING(word, 1, 1)
FROM extracted_words
WHERE (SUBSTRING(word, 1, 1) COLLATE latin1_bin) = UPPER(SUBSTRING(word, 1, 1))
AND (SUBSTRING(word, 2, 1) COLLATE latin1_bin ) = LOWER(SUBSTRING(word, 2, 1)) This query will select the following words:
Xxxxx
Yyyyy
Yyyyy-ZzzzBut NOT the following words:
XYZ
zxxzxSet an extra column in your search result telling if a string is upper or lower case by comparing the second character with the same character in that position, but transformed to upper case withe UPPER().
<?php
SELECT OrtNamn, IF( (
UPPER( SUBSTRING( OrtNamn, 2, 1 ) ) = ( SUBSTRING( OrtNamn, 2, 1 )
COLLATE latin1_bin ) ) , "upper", "lower"
) AS thecase
FROM `orter`
WHERE 1
ORDER BY `thecase` ASC
?>