CST 363 Week 2 Journal Entry
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
One example of this would be if a customer is in a city and wants to know what stores there are. If there is a customer table with id, name, and city and then a stores table with id, name, and city, we can use city as the shared attribute since it is. not a primary or foreign key.
"Find all customers and the stores that are located in the same city as the customer."
SELECT
c.customer_id,
c.name AS customer_name,
s.store_id,
s.store_name
FROM
customers c
JOIN
stores s
ON
c.city = s.city;
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?
I like SQL. I think it is simple enough as it is fairly close to English yet also has its own unique syntax. I don't think it is pretty easy to learn but I think with practice you kind of get the hang of it and see how it works. When converting English to SQL I just take some time to think about what tables I'll need and which table to join, that is what is challenging to me.
Comments
Post a Comment