I started studying SQL from a very famous site - HackerRank. Here I will try to provide multiple approaches & solutions to the same problem. It will help you learn and understand SQL in a better way.
Please make use of my blog posts for learning purpose only and feel free to ask your questions in the comment box below in case of any doubt.
Click Here for the previous blog-post in the series.
SQL Problem Statement:
Query the list of CITY names ending with vowels (i.e., a, e, i, o, or u) from STATION. Your result cannot contain duplicates.
The STATION table is described as follows:
Table: STATION |
Sample data in Table (STATION):
Solution-1: Using LIKE Function (MySQL Query):
Solution-2: Using REGEXP_LIKE Function (MySQL Query):
NOTE:
- "$" character in REGEXP_LIKE function is used to check string ending with matching pattern.
- "[]" (square brackets) are used to pass the list of characters to check. Here, it is a,e,i,o,u.
- "i" is passed as an argument to the REGEXP_LIKE function for case_insensitivity. i.e. It will try check match with small as well as capital letters.
Solution-3: Using RIGHT Function (MySQL Query):
NOTE:
- The RIGHT function is used to take a substring of CITY starting from the right, and "1" is passed as an argument to select only 1 character from the right.
Sample Output:
--------------------------------------------------------------------------------
Click here to see solutions for all Machine Learning Coursera Assignments.
&
Click here to see more codes for Raspberry Pi 3 and similar Family.
&
Click here to see more codes for NodeMCU ESP8266 and similar Family.
&
Click here to see more codes for Arduino Mega (ATMega 2560) and similar Family.
Feel free to ask doubts in the comment section. I will try my best to answer it.
If you find this helpful by any mean like, comment and share the post.
This is the simplest way to encourage me to keep doing such work.
Thanks & Regards,
-Akshay P Daga