Skip to content
Advertisement

Get all employee detail from employees table whose “First_name” start with any single character between ‘a-p’

SELECT
    *
FROM
    employees
WHERE
    first_name LIKE 'A%'
    OR first_name LIKE 'B%'
    OR first_name LIKE 'C%'
    OR first_name LIKE 'D%'
ORDER BY
    first_name;

is there any new way to rewrite the SQL Query to find the first_name starting from A to P

Advertisement

Answer

Use regexp_like:

select *
from employees
where regexp_like(first_name, '^[a-p]', 'i')

The regex breakdown:

  • ^ means “start of text”
  • [a-p] means “any character in the range à to p inclusive”
  • The i flag means “ignore case”
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement