CST 363 Weekly Journal #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 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.
- One example where joining on something other than keys would be needed could be how products and sales work. For example, the query is to retrieve all sales transactions where the product name in the Sales table partially matches the product name in the Products table as an English sentence. The query in SQL would be:
Select *
From Sales
Join Products p ON s.product_name LIKE CONCAT('%', p.product_name, '%');
Comments
Post a Comment