'Query in SQL to display the employees whose Second character of their name is between 'A' and 'M'
I tried these, but none of them seem to work. Can someone help me please?
SELECT ename AS "Employee Name"
FROM emp
WHERE ename BETWEEN LIKE ('_A%' AND '_M%');
SELECT ename AS "Employee Name"
FROM emp
WHERE ename BETWEEN LIKE '_A%' AND LIKE '_M%';
Solution 1:[1]
This might be a pretty old post, but since no one has answered yet, here is my take on it (keep in mind that this might not be the only way or the best way in any case as I'm not very experienced yet):
SELECT ename AS "Employee Name"
FROM emp
WHERE UPPER(SUBSTR(ename, 2, 1)) BETWEEN 'A' AND 'M';
The UPPER function is not necessary if your data is in all caps, but just in case it's not.. And also, if you want to select the data where the second letter of field ename is between 'A' and 'M', both inclusive, you might want to try using BETWEEN 'A' AND 'N' instead, because when I tried the code using my sql developer, the expression after the AND statement in BETWEEN function is exclusive. Hope this helps :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Grandevox |
