开发者

Finding a substring from a database in MySQL

开发者 https://www.devze.com 2023-04-07 16:57 出处:网络
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 al开发者_如何学Cex and alexandra.

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 al开发者_如何学Cex and alexandra.

how do i do this in MySQL? please help.


select *
from tableName
where name like 'al%'


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%'


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消