- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I search for names starting with A in MySQL?
Use LIKE for this, as shown below −
select *from yourTableName where yourColumnName LIKE 'A%';
Let us first create a table −
mysql> create table DemoTable ( StudentName varchar(100) ); Query OK, 0 rows affected (0.66 sec)
Now you can insert some records in the table using insert command −
mysql> insert into DemoTable values('John Smith'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('Adam Smith'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Aaron Taylor'); Query OK, 1 row affected (0.43 sec) mysql> insert into DemoTable values('Chris Brown'); Query OK, 1 row affected (0.27 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+--------------+ | StudentName | +--------------+ | John Smith | | Adam Smith | | Aaron Taylor | | Chris Brown | +--------------+ 4 rows in set (0.00 sec)
Following is the query to search for names starting with A in MySQL −
mysql> select *from DemoTable where StudentName LIKE 'A%';
Output
+--------------+ | StudentName | +--------------+ | Adam Smith | | Aaron Taylor | +--------------+ 2 rows in set (0.00 sec)
- Related Articles
- How do I search a list in Java?
- How do I write class names in Java?
- How do I write method names in Java?
- How do I write variable names in Java?
- How do I write constructor names in Java?
- How do I write interface names in Java?
- How do I write package names in Java?
- How do I write constants names in Java?
- Can I search for particular numbers in a MySQL column with comma separated records using a MySQL query?
- How do I search and replace specific chars at the beginning of a string in MySQL?
- How do I view the auto_increment value for a table in MySQL?
- How do I set the default value for a column in MySQL?
- Search for specific characters within a string with MySQL?
- How do I return multiple results in a MySQL subquery with IN()?
- How do I create dynamic variable names inside a JavaScript loop?

Advertisements