Prompt
SQL has the flexibility to join tables on any column(s)
using any predicate (=, >, < ). As long the column(s) are type
compatible. 98% of the time the join uses primary key of one table,
foreign key of the other table and equal predicate. Think of example
where joining on something other than keys would be needed. Write the
query both as English sentence and SQL. If you can't think of your own
example, search the internet for an example.
Response
One example of such a query could be utilized in online
retail to determine which customers made an order within the first day of creating
their online account. The customer table would have an account_created_date field
and the orders table would have an order_date field. Comparing these
non-primary keys would give us this bit of information.
SELECT customer_name
FROM customers c JOIN orders o
ON
c.account_created_date = o.order_date;
No comments:
Post a Comment