In: Computer Science
1.We sell music to our members. Employees recommend titles by rating them from1 to 5 with 1 being not very good to 5 being very good
What would your strategy be to write SQL code for the following query: "Show all the members and the sale dates of products they bought if they bought any products"
I would use a left outer join |
|||||||||||||||||
I would not use a join because the data comes from one table |
|||||||||||||||||
I would use an equality join to find matching records in two or more tables by matching primary and foreign keys |
|||||||||||||||||
I would use a subquery |
|||||||||||||||||
I would use a recursive join to join a table to itself 2. We sell music to our members. Employees recommend titles by rating them from1 to 5 with 1 being not very good to 5 being very good What would your strategy be to write SQL code for the following query: "Show every artist and product we carry and the sale date of the product it it has ever been sold"
|
For the 1st one, I will use the an equality join to find the matching records in two or more tables by matching primary and foreign keys
Description: Here we need Member, Title and Price of the product
member have bought. These details are existing in 3 different
tables : Member, Sale and Product. (This negates the second option
that says that data comes from a single table). As we need the
details of the members who bought the product we will need to use
the equality join, which works by comparing the Primary and Foreign
keys.
We cannot use the LEFT JOIN as that will generate extra rows e.g.
if we keep Product table as left most table then our query will
give data for those products as well for which no sale has been
done. We will not use subquery as there is no conditional checking
required. We will not use the recursive join as that is mainly used
for comparing the rows of a table with itself which is not
required.
For 2nd :
I will use left outer join of product and sale table as we need
every artist as result and sales if any per product
Query will be
SELECT * FROM Product LEFT JOIN Sale ON Product.productid ==
Sale.productid
Please do upvote thank you.