Wednesday, May 14, 2025

CST363: Week 2 (Week 18)

 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.

If a manufacturer imports raw materials, a Materials table migth contain columns for the material name (e.g. aluminum, lithium, lumber, etc.), supplier name, and address fields for the supplier including a column for the country. In that case the primary key would be a composite key formed by the material name and the supplier name.
A second table tracking tariff percentages might have a column for country ID (primary key), country, and tariff rate.
The join could be done using the country columns as follows to show what tariff rate is associated with each supplier:
SELECT *
FROM Materials M
INNER JOIN Purchases P
ON M.country = P.country;

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?

So far, SQL hasn't been too difficult to learn. I would rate it as moderate difficulty since on one hand it is completely new to me and on the other hand the reserved words and organization are relatively intuitive. I need to spend more time reviewing the nested queries and the join operations to really get comfortable with them. They don't always translate to English as easily so it takes a bit more thought for me sometimes to see what is happening.

No comments:

Post a Comment

CST363: Week 8 (Week 24)

 The three most important things I learned in this course: 1) What databases are and their advantages over for example, a flat file or sprea...