Tuesday, May 13, 2025

CSUMB Week 17 (7 May 2025 - 13 May 2025)

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.

The best way I am understanding this is that a key-based join establishes a "formal" relationship (as in it uses a primary and foreign key pair) and essentially always uses an equal sign (=). Whereas a non-key based join is an "informal" relationship where a relationship might not always be valid. Non-key based joins can also use predicates such as <, >, LIKE, BETWEEN, etc. 

for example:

"Given 2 tables called: student and grade, find students based on a range of a given grade"

We might see something like

SELECT student.name, student.id, grade.percentage

FROM student

JOIN grade ON grade.percentage BETWEEN 40 AND 60

WHERE student.name = grade.student_name;


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 found SQL exceptionally easy to use and learn. The kinds of questions that gives me the most challenge is when it required multiple nested subqueries. Even then I think I am getting used to that part as well.

No comments:

Post a Comment