BITS_Python
BITS_Python

Reputation: 381

Finding a substring from a database in MySQL

I have a Database like this"

NAME - AGE
alex - 20
mathew - 14
alexandra-31
human-10

now in a text box elsewhere when i type say "al",I should get the result as alex and alexandra.

how do i do this in MySQL? please help.

Upvotes: 1

Views: 60

Answers (3)

Adriano Carneiro
Adriano Carneiro

Reputation: 58595

Select name, age
From yourtable
Where name like 'al%'

Or, if you want to type any part of the name:

Select name, age
From yourtable
Where name like '%le%'

Upvotes: 1

Tom Mac
Tom Mac

Reputation: 9853

create table your_table
(NAME varchar(50),AGE int);

insert into your_table (NAME,AGE) values ('alex',20);
insert into your_table (NAME,AGE) values ('mathew',14);
insert into your_table (NAME,AGE) values ('alexandra',31);
insert into your_table (NAME,AGE) values ('human',10);

select NAME from your_table where name like 'al%';

Should do the trick...

Upvotes: 0

Karolis
Karolis

Reputation: 9562

select *
from tableName
where name like 'al%'

Upvotes: 1

Related Questions