CST 363 Week 2
- 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 an 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
An example of joining 2 tables without a common column or matching key is using a cross join. A cross join creates a new table from all possible combinations of 2 existing tables. This may be practical for pricing computers based on its model and size of its screen. The query below would create a record that represents a possible combination of computer model and screen size along with its given price.
SELECT model, screen_size, computer.price + screen.price FROM computer CROSS JOIN screen;
- 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 is an interesting language. I have not worked much with databases before this class so this material is very new to me. Up to this point though, everything has made sense to me, and I can see how language would be practical in the workplace. Some of the problems I have dealt with this week seemed complex at first, but working on individual sub queries one at a time has made solving these problems feel much easier. As of right now, I have faced the most issues with dealing with aggregation. Knowing when to use 'where' or 'having' when filtering a query caused some problems for me earlier in the week. I also had to pay more attention to when a sub query should return multiple rows or just one
Comments
Post a Comment