How to Display Employee Names Starting With a and Then B in SQL

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

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.

SQL query to get names containing a and b anywhere in the string

I'm guessing you are currently getting 0 rows returned, because you're querying for FName values that end with a and end with b. You're close though.

Just add another wild card to the end of each like criteria, and it'll look for matches where anything proceeds, or follows, each letter (including beginning or ending of the string).

select FName from Employee where FName like '%a%' AND FName like '%b%'

More information on LIKE:
https://msdn.microsoft.com/en-us/library/ms179859(v=sql.110).aspx

how to get count of employees whose name starts with alphabet A and B

You can always use CASE

 SELECT 
SUM(case when first_name like 'A%' then 1 else 0 end) 'A' ,
SUM(case when first_name like 'B%' then 1 else 0 end) 'B'
FROM tableName

Query basically means add 1 to column A for every first_name that starts with A.

List the employees whose name starts with 'S' and ends with 'S'?

It looks like Informatica does not have a LIKE equivalent available. You can use REG_MATCH and insert in a regular expression that will match for starts with S and ends with S. Example Below:

REG_MATCH(ENAME,'[S^]+\w+[S$]')

RegExr Link: http://regexr.com/3b17b

I want to know SQL commands

select *
from employee
where
name like's%'
and
name like'%h';

SQL - print names with letter starting in 's' or ending in 's'. Exclude Males

You can use the like operator with the asterisk (*) in Access. the * wildcard represents any number of characters in a string.

SELECT pet_id, Name, Type, Breed, Gender
FROM pet
WHERE (Name LIKE "s*" OR Name LIKE "*s")
and gender <> "M"

MS Access uses the asterisk (*) wildcard character instead of the percent sign (%) wildcard character.



Related Topics



Leave a reply



Submit