
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Get the names beginning with a particular character using LIKE in MySQL
To get the names beginning with a particular character, you need to use LIKE. Let us first create a table:
mysql> create table DemoTable ( StudentFirstName varchar(20) ); Query OK, 0 rows affected (1.01 sec)
Following is the query to insert some records in the table using insert command:
mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Carol'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Johnny'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Ramit'); Query OK, 1 row affected (0.18 sec)
Following is the query to display records from the table using select command:
mysql> select *from DemoTable;
This will produce the following output:
+------------------+ | StudentFirstName | +------------------+ | John | | Carol | | Johnny | | Robert | | Chris | | Ramit | +------------------+ 6 rows in set (0.00 sec)
Following is the query to match the first character with LIKE: i.e. all students with first name beginning from character C:
mysql> select *from DemoTable where StudentFirstName LIKE 'C%';
This will produce the following output:
+------------------+ | StudentFirstName | +------------------+ | Carol | | Chris | +------------------+ 2 rows in set (0.00 sec)
- Related Articles
- Select particular type of columns beginning with a certain letter and concatenate the names
- Find the records with % character in a LIKE query with MySQL
- How can I check the character set of all the tables along with column names in a particular MySQL database?
- In MySQL, how can we get the number code of a particular character?
- Get field value and convert a particular character from it to uppercase with MySQL
- Find all the names beginning with the letter 'a' or ‘b’ or ‘c’ using MySQL query?
- Display specific table names with MySQL LIKE Operator
- Get the number of rows in a particular table with MySQL
- Get table names using SELECT statement in MySQL?
- MySQL query to select all fields beginning with a given number with next character a letter?
- MySQL ORDER BY CASE to display special character in the beginning
- How to replace a particular character in a MySQL column?
- Finding only strings beginning with a number using MySQL Regex?
- How to use MySQL LIKE clause to fetch multiple values beginning with “Joh”
- How to get the maximum value from a column with alphanumeric strings beginning with specific characters in MYSQL?

Advertisements