SQL query to check whether the name is begin and ends with consonants

Viewed 37

I am trying to retrieve the names from a student table starting and ending with consonants. I am trying to write

SELECT NAME
FROM STUDENT
WHERE NAME-LEFT(NAME,1) IN ('A','E','I','O','U')
AND NAME-RIGHT(NAME,1) IN ('A','E','I','O','U');

trying to omit the vowel's term, then the rest terms automatically become consonants, but I think there is an error in SQL query as I am also getting the terms that are started with vowels. How to fix this?

1 Answers
SELECT NAME
  FROM STUDENT
 WHERE LEFT(UPPER(NAME),1) NOT IN ('A','E','I','O','U') /*change done is to extract the first letter*/
   AND RIGHT(UPPER(NAME),1) NOT IN ('A','E','I','O','U'); /*change done is to extract the last letter*/

Edit: from feedback of Akina, added the condition to cater to non vowels, and assumption made that the collation characteristics match

Related