LittleMissChoco
LittleMissChoco

Reputation: 19

MySQL statements -- Pattern Matching etc

display all rows where the hiredate is before april 1, 1981 and the employee name is from A to S

This is the code that I have done and it doesn't work. :( When I tried to put AND between '%A' and '%S' it doesn't work either. :( When I deleted the '%S' it worked but it will only retrieve the record with a name starting with letter A. :(
Can you guys help? I really don't know what to do. :(

SELECT * 
FROM tblEmployee 
WHERE HIREDATE < '1981-04-1' 
 AND ENAME LIKE '%A' '%S'

Thanks. ^^

Upvotes: 0

Views: 65

Answers (3)

xkeshav
xkeshav

Reputation: 54084

TRY

SELECT * FROM tblEmployee WHERE HIREDATE < '1981-04-1' AND ENAME REGEXP '^[a-s]+$'

REFERENCE

Upvotes: 0

Yahia
Yahia

Reputation: 70369

Use

SELECT * FROM tblEmployee WHERE HIREDATE < '1981-04-01' AND SUBSTR ( ENAME, 1, 1 ) BETWEEN 'A' AND 'S'

Upvotes: 1

ypercubeᵀᴹ
ypercubeᵀᴹ

Reputation: 115660

You were close. I guess you want names starting from A, B, C, ... S (not ending in A-S). Right?

If yes, try this:

SELECT * 
FROM tblEmployee 
WHERE HIREDATE < '1981-04-01'    --- notice the  -01
  AND ENAME >= 'A' 
  AND ENAME < 'T'

Upvotes: 1

Related Questions