Week 02 - CST363-30-2253- Intro to DB Systems
05/23/2035
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.
- English sentence: Assuming there’s an online car
dealership website similar to CarMax, you’re searching to buy a daily driver,
but need to filter a min and max price range. That way it’s not too old, but at
the same time it’s not a new release that’s out of budget.
- The cars table stores info such as price, model,
make.
- The customer_search table stores MIN/MAX per individual
customer.
- SQL:
SELECT
c.id,
c.price,
c.model,
c.make,
c.price,
cust.customer_id
cust.budget_min,
cust.budget_max,
FROM
customer_search cust
JOIN
cars c
ON
c.price BETWEEN
cust.budget_min
AND
cust.budget_max;
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 as a language is very well designed, it is not easy to learn because there is so many different functions and it can get very complex, but if we break each query down into smaller queries, then it is easier to understand and utilize. When translating from English question to SQL, the most difficult part is trying to remember or research what function can be used to properly solve the question being requested in the most efficient manner & to order everything in a logic manner, where it'll execute the query systematically.
Comments
Post a Comment