CST 363 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.

One example where joining on something other than keys is needed involves combining tables based on a non-key attribute. For instance, if I want to find customers who have made purchases in the same month, I might join the Customers table with the Orders table based on the order date and customer ID. The SQL query would look like this:

SELECT c.CustomerID, c.CustomerName, o.OrderID, o.OrderDate
FROM Customers c
JOIN Orders o
ON c.CustomerID = o.CustomerID
AND EXTRACT(MONTH FROM o.OrderDate) = EXTRACT(MONTH FROM CURRENT_DATE);

In this query, I'm joining the Customers and Orders tables on the CustomerID and additionally filtering by the month of the order date, rather than just using keys.

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 find SQL to be a powerful and versatile language for managing and querying databases, though it can be somewhat challenging at first. Its syntax is generally straightforward, making basic queries easy to learn and use. However, translating complex English questions into SQL can be tricky, especially when it involves multiple joins, subqueries, and aggregations. Crafting queries that accurately reflect intricate conditions or relationships often requires a deep understanding of both the data and the language's more advanced features.

Comments

Popular posts from this blog

CST 334 Week 4

CST363 Week 1

CST 334 Week 7