Week 2 - SQL Joins
SQL has the flexibility to join tables on any column(s) using any predicate (=, >, < ). Most of the time the join will use equality between a primary and foreign key. Think of example where joining on something other than keys would be needed. Write the query both as an English sentence and in SQL. If you can't think of your own example, search the textbook or internet for an example.
An example where joining on something other than keys would be needed is when you would want to join two tables such as a Student table where total credits are needed to graduate and a Program/Major table that has a column of required credits to graduate from the program. In this scenario the idea is to check which students are able to graduate from certain programs basing it off whether their current credits are greater than or equal to the credits required to graduate in the program.
A query in English for this example would be to join the Student and Program tables to find all the students whose total credits are greater than or equal to the credits required for the program.
An SQL example would be
SELECT student.id, student.name, student.total_credits, program.name, program.req_credits
FROM student
JOIN program ON student.total_credits >= program.req_credits
What is your opinion of SQL as a language? Do you think it is easy to learn and use? When translating from an English question to SQL, what kinds of questions do you find most challenging?
The SQL language has been very fun to explore as of this course. Before I was quite intimidated by the numerous queries in the ROOM database for Android Studio with SQLite, for example the simple CRUD statements and use of LiveData made it a bit confusing for me to completely understand the syntax of SQL. I was just kind of using them without really understanding their actions. Personally, I think SQL is quite easy to learn but there are some difficult hurdles to get over; for example understanding all the keywords, clauses, and knowing when to utilize the different JOINS. I had to keep a notepad of all the different keywords on my second monitor and zybooks opened while doing most of the labs this week. I will say though, that once you find a rhythm to most of the problems they start becoming straightforward. As of right now, I find the most difficult questions when translating from an English question to SQL are the requirements of sub-queries and the joining of multiple tables. This week has been a big step forward because now I am required to analyze multiple table's columns and rows to make sure they are properly joined or displaying the correct results with the sub-queries. Next week I definitely need to start reviewing and practicing twice as much for the exam.
Comments
Post a Comment