Intro to Database Systems Week 2
1. 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 query that might require joining without using equality between primary and foreign key is when there is no primary and foreign key to compare. For example, a table "Employees" exists with columns primary key ID, name, manager, and salary, and a table "Department" exists with columns primary key code, dept_name, size, and manager. With this a question is posed: Can you list all employees, their department name, and salary? An SQL query could be the following:
select name, dept_name, salary from Employees inner join Department on Employee.manager = Department.manager;
2. 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?
SQL is an important language that allows users to efficiently gather, filter and analyze large sets of data. I think the language is easy enough that it can be picked up and used swiftly at a beginner level. However, the language can get more difficult to use when more complex queries need to be made, where a user needs to understand what certain operations really mean. When translating questions to SQL I find questions that require gathering and joining information from more than two tables more challenging.
Comments
Post a Comment