CST 363 Week 02
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.
Scenario: Two data tables Employees and Projects. The Employees table contains a column of their joining date. The Projects contains a column of their starting date. We need to find which employees were hired before the project started.
English Sentence: Join the Employees with the Projects to find which employees are hired before the project's start date.
SQL Query:
SELECT Employees.ID, Employees.Name, Projects.ProjectName
FROM Employees
JOIN Projects ON Employees.JoiningDate < Projects.StartDate;
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 easier to learn and use compared to other programing language. However, as the requirements are getting more complicated, SQL is also not easy to handle. But SQL have some powerful tool (such as VIEW, UNION) to make things smoother. The questions are, do I know which one to use and which one is the best.
The challenge when translating from an English question to SQL for me is to figure out where to start. I need to know what tables to use, join with what key and how to narrow it down to approach the result.
.png)
Comments
Post a Comment