1

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.

2

3 Answers 3

1
select *
from tableName
where name like 'al%'
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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

2 Comments

Based on your answer, I think you should complete your LIKE - statement. In my eyes use: ... like '%al%'
Fair enough. I guess it depends on what the guy wants to come back in his text box. If you completed the LIKE statement with '%al%' then names such as 'hal' and 'malcolm' would come back when entering 'al' as well as 'alex' and 'alexandra' instead of just 'alex' and 'alexandra'. Thanks for the comment though!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.