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.
A scenario where keys wouldn't be necessary is finding pairs of instructors and students where the student's total credits are greater than the instructor's years of service. "List instructors and students where the student's total credits exceed the instructor's years of service."
SELECT
i.name AS instructor_name,
s.name AS student_name,
i.years_of_service,
s.tot_cred
FROM instructor i
JOIN student s ON s.tot_cred > i.years_of_service; -- Join on inequality
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 think SQL as a language is super neat and important to learn. The basics are easy, but as the prompt gets more complex, so does the SQL code. There is certainly a learning code. I had a lot of trouble using the select max statements from Homework #2.
Comments
Post a Comment