CST363 Week 2

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 of where a join does not rely on primary or foreign keys is matching records based on dates instead of IDs. An example would be if I have a table called Sales and a Promotions table as well, I may want to be able to see which sales occurred on the same date as a promotion. The English version of the question would be something like "Show all sales and promotions that occurred on the same date." The SQL form being:

Select Sales.sale_id, Sales.sale_date, Promotions.promo_name

From Sales

Join Promotions

On Sales.sale_date = Promotions.promo_date;

Aligning time periods or ranges is an example of utilizing this type of join when the relationship between tables is based on something other than a key match.


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?


I believe that SQL as a language is that it is powerful but it definitely takes time to practice and feel comfortable working with. I like how it is straightforward in the sense that queries often read almost in English. However, there are challenges that come with making the structure for more complex subqueries. I think that translating English into SQL to be the easiest when the question is direct. It tends to become more difficult when the questions become more abstract. More complex questions require breaking it down into smaller steps. Overall, I think SQL is fairly straightforward, but the hard part is deciding how to translate the logic of a problem into the correct sequence of commands.

Comments

Popular posts from this blog

Week 4 - Goals!

Week 2 - Second week of class!

Week 4 - Interview with Industry Expert