Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display employee names starting with a and then b in sql

Tags:

sql

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

like image 891
Linux world Avatar asked Sep 17 '10 22:09

Linux world


1 Answers

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 it just gets translated to the following which is.

WHERE  employee_name >= 'A'
       AND employee_name < 'C' 

For all variants you would need to consider whether you want to include accented variants such as Á and test whether the queries above do what you want with these on your RDBMS and collation options.

like image 104
Martin Smith Avatar answered Sep 21 '22 14:09

Martin Smith