tags:

views:

75

answers:

6

i want to display the employee names which having names start with a and b ,it should be like list will display employees with 'a' as a first letter and then the 'b' as a first letter...

so any body tell me what is the command to display these...

+2  A: 
select columns
  from table
 where (
         column like 'a%' 
      or column like 'b%' )
 order by column asc
cfEngineers
+1 You were first.
Martin Smith
we shall share in the glory :-)
cfEngineers
+4  A: 

To get employee names starting with A or B listed in order...

select employee_name 
from employees
where employee_name LIKE 'A%' OR employee_name LIKE 'B%'
order by employee_name

If you are using Microsoft SQL Server you could use

....
where employee_name  LIKE '[A-B]%'
order by employee_name

This is not standard SQL though.

Martin Smith
its working but i want to display in alphabetical order like the names with a letter should be first and then the names with b letter
lak in iphone
@lak in iphone: So what exactly are you trying to do? I mean, these answers are all pretty much the same, and from what I can understand from your question - correct. It sounds to me that you should either try doing some research on your own before asking the question or define the question better so we can help you.
skajfes
A: 

What cfengineers said, except it sounds like you will want to sort it as well.

select columns
  from table
 where (
         column like 'a%' 
      or column like 'b%' )
order by column

Perhaps it would be a good idea for you to check out some tutorials on SQL, it's pretty interesting.

Cyrena
A: 

If you're asking about alphabetical order the syntax is:

SELECT * FROM table ORDER BY column

the best example I can give without knowing your table and field names:

SELECT * FROM employees ORDER BY name
Alex
Is there something wrong with my suggestion? Why would it get a downvote?
Alex
It wasn't from me. I suspect it is because the question says that they want names starting with a and b and your answer doesn't handle that. I wouldn't be massively surprised though if it was to turn out that the question is badly worded and your interpretation is correct.
Martin Smith
Precisely, I suspected the wording wasn't exactly right, and he was looking for alphabetical order, not strictly A and B names only in alphabetical order. If my interpretation is incorrect, it's incorrect, but you cant fault me for trying my best to answer someones question which isn't very easy to understand.
Alex
A: 

select * from stores where name like'a%' or name like 'b%' order by name

lak in iphone
this will only work for names starting with a or b, you need to use the answer I posted to sort alphabetically A-Z
Alex
A: 
select name_last, name_first
from employees
where name_last like 'A%' or name_last like 'B%'
order by name_last, name_first asc
JohnB