MySQL search between two letters

I have a long list of company names, but I only want results in which the result set will return companies starting with the letters AE.

Is it possible?

+3


source to share


5 answers


Try to use LIKE

SELECT *
FROM   tableName
WHERE  CompanyName LIKE 'A%' OR
       CompanyName LIKE 'B%' OR
       CompanyName LIKE 'C%' OR
       CompanyName LIKE 'D%' OR
       CompanyName LIKE 'E%' 

      

or REGEXP

SELECT * 
FROM   tableName
WHERE  CompanyName REGEXP '^[A-E]';

      



other (s)

+4


source


You can (also) do this with a simple string comparison;

SELECT *
FROM Companies 
WHERE CompanyName >= 'a'  
  AND CompanyName <  'f';  -- to be sure to get _all_ companies on 'E' 

      



Simple SQLfiddle .

+2


source


Company names starting with A

, E

with LEFT

. If you need to finish, you can also use RIGHT

.

SELECT * 
FROM   YOURTABLE
WHERE  LEFT(CompanyName,1) IN ('A', 'E')
;

      

+1


source


SELECT * FROM mytable WHERE company_name < 'F';

      

0


source


SELECT name FROM TABLE_NAME WHERE name BETWEEN 'a' AND 'e'

      

OR

SELECT Name FROM Employees WHERE Name REGEXP '^[A-E].*$'

      

0


source







All Articles