Fetch a specific column value (name) in MySQL


To fetch a specific column value, use LIKE clause. Let us first create a table −

mysql> create table DemoTable1809
     (
     Name varchar(20)
     );
Query OK, 0 rows affected (0.00 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1809 values('John');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1809 values('David');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1809 values('Mike');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1809 values('Johnson');
Query OK, 1 row affected (0.00 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1809;

This will produce the following output −

+---------+
| Name    |
+---------+
| John    |
| David   |
| Mike    |
| Johnson |
+---------+
4 rows in set (0.00 sec)

Here is the query to fetch a specific value

mysql> select * from DemoTable1809 where Name LIKE 'Johnson%';

This will produce the following output −

+---------+
| Name    |
+---------+
| Johnson |
+---------+
1 row in set (0.00 sec)

Updated on: 24-Dec-2019

605 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements