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)