I’m a beginner in SQL and I use MySQL database.
I have a table called "employees".
How to retrieve only those employees whose third or any letter after the third is "r"?
I have to use the LIKE operator.
What I’ve tried:
SELECT * FROM employees WHERE last_name LIKE "__r%"
, but I think it only retrieves those employees who have "r" as the third letter in their last name.
2
Answers
Almost there. You just need another wildcard before the
r
(the wildcard can also match 0 characters).Or, you could use
Substring()
:Either way, the performance will not generally be great, as you’ll have to evaluate every row in the table (even if you only want a few), and indexes won’t be very helpful.