Query the list of CITY names from STATION which have vowels (i.e., a,
e, i, o, and u) as both their first and last characters. Your result
cannot contain duplicates.
SELECT DISTINCT CITY FROM STATION WHERE CITY REGEXP '^[aeiou]' AND CITY REGEXP '[aeiou]$'
Why was this solution downvoted a lot in a forum? Is there any performance issue with a query like that, or is it bad practice somehow?
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
No, there is no performance issue with using these. They are instead faster way of searching strings in comparison to nested queries. On HackerRank forum, I have seen many other course comments also where answers were right but people were just downvoting. Though the two lines in ‘where city REGEXP’ part can be combined and written in one line, the time complexity for both will be same. If you want to know more about Regex in MySQL, you can follow this post :-