SQL Query to Check If a Name Begins and Ends With a Vowel
Last Updated :
08 Oct, 2021
In this article, we will see an SQL query to check if a name begins and ends with a vowel and we will implement it with the help of an example for better understanding, first of all, we will create a database Name of the Database will GeeksforGeeks. and inside the database, we will create a table name As “Student”.
Here we use two different methods for this.
Syntax:
FOR LEFT():
LEFT ( expression, no_of_chars needed to the left)
FOR RIGHT():
RIGHT ( expression, no_of_chars needed to the right)
In this article let us see how to Check If a Name Begins and Ends With a Vowel and display them using MSSQL as a server.
Step 1: Creating a database
Creating a database GeeksforGeeks by using the following SQL query as follows.
Query:
CREATE DATABASE GeeksforGeeks;

Step 2: Using the database
Using the database GeeksforGeeks using the following SQL query as follows.
Query:
USE GeeksforGeeks;

Step 3: Creating a table
Creating a table student with 3 columns using the following SQL query as follows.
Query:
CREATE TABLE student(
stu_id VARCHAR(8),
stu_name VARCHAR(30),
stu_branch VARCHAR(30)
)

Step 4: Verifying the database
To view the description of the table using the following SQL query as follows.
Query:
EXEC sp_columns student

Step 5: Inserting data into the table
Inserting rows into student tables using the following SQL query as follows.
Query:
INSERT INTO student VALUES
('191401', 'ABHI','E.C.E'),
('191402', 'OLIVIA','E.C.E'),
('191403', 'SAMARTH','E.C.E'),
('191404', 'ANNABELLE','E.C.E'),
('191405', 'ARIA','E.C.E'),
('191406', 'RAMESH','E.C.E')

Step 6: Verifying the inserted data
Viewing the table student after inserting rows by using the following SQL query as follows.
Query:
SELECT * FROM student

Step 7: Query to Check If a Name Begins and Ends With a Vowel using string functions and IN operator
Method 1:
To check if a name begins ends with a vowel we use the string functions to pick the first and last characters and check if they were matching with vowels using in where the condition of the query. We use the LEFT() and RIGHT() functions of the string in SQL to check the first and last characters.
Query:
SELECT stu_name
FROM student
WHERE LEFT(stu_name , 1) IN ('a','e','i','o','u')
AND RIGHT(stu_name,1) IN ('a','e','i','o','u')
Output:

Method 2:
Using Regular Expressions and LIKE operator to check if first and last characters are vowels. Query to Check If a Name Begins and Ends With a Vowel using REGEX
Query:
SELECT stu_name
FROM student
WHERE stu_name LIKE '[aeiouAEIOU]%[aeiouAEIOU]'
Here % is used for multiple occurrences of any character and [] is used for anyone occurrence of a given set of characters in the brackets.
Output:
Similar Reads
SQL Query to Match City Names Ending With Vowels (a,e,i,o,u) To match the names of cities ending with a vowel, use the LIKE operator with % wildcard. This matches all cities that end with a vowel. Here is a SQL query to match city names ending with vowels (a,e, i,o,u). Query:SELECT EMPNAME,CITY FROM office WHERE CITY LIKE %[aeiou]Example DatabaseTo use this q
1 min read
PHP Program to Check Whether a Character is a Vowel or Consonant There are a total of 26 letters in the English alphabet. There are 5 vowel letters and 21 consonant letters. The 5 vowel letters are: "a", "e", "i", "o", and "u" rest are consonants. There are different approaches to checking whether a character is a vowel or a consonant. These are the different App
3 min read
No. of vowels and consonants in a given string in PL/SQL Prerequisite - PL/SQL introduction In PL/SQL code groups of commands are arranged within a block. A block group related declarations or statements. In declare part, we declare variables and between begin and end part, we perform the operations. Given a string and the task is to find the number of vo
2 min read
SQL Query to Find the Name of a Person Whose Name Starts with Specific Letter Here, we are going to see how to find the name of a person whose name starts with a specified letter in SQL. In this article, we will be making use of the Microsoft SQL Server as our database. For example, finding the name of the person whose name starts with the letter "H". We will use the % symbol
2 min read
How to check a string starts/ends with a specific string in PHP ? In this article, we are going to learn how to check that a given string is starting or ending with a given specific string in PHP.We require the use of XAMPP, Netbeans to run this code.Input: "Geeks For Geeks"Starting with: "G"Output: "Geeks For Geeks Starts with String G"In PHP version 8+, there ar
2 min read
How to Select Words With Certain Values at the End of Word in SQL? Selecting words from a string with specific values at the end can be crucial in SQL for tasks like filtering data, pattern matching, and extracting relevant information. In SQL, we often need to work with strings where we need to find words ending with certain characters or patterns. This guide will
4 min read