
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get 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)
Advertisements