-2

I have three tables:

product(pid,name,category,maker-cid)
purchase(buyer-ssn,seller-ssn,quantity,pid)
person(ssn,name,phone number,city)

How can I create a view to expose only the Buyer name, Seller name and product name from all transactions?

2
  • 1
    Are you asking this with regard to a specific database product (if so, which) or are you looking for a universal solution (if so, why)?
    – Andriy M
    Oct 9, 2015 at 16:45
  • i just had problem dealing with this question as i was learning about the concept of view.so, the universal solution is also accepted.
    – Nawin
    Oct 9, 2015 at 16:49

1 Answer 1

5

You just need to join the tables, projecting out the columns you need and wrap that in a view. For example:

CREATE VIEW "view name"
AS
SELECT 
    B.Name "Buyer Name",
    S.Name "Seller Name",
    PRD.Name "Product Name"
FROM Purchase PUR
JOIN Person B 
    ON B.ssn = PUR."buyer-ssn"
JOIN Person S 
    ON S.ssn = PUR."seller-ssn"
JOIN Product PRD 
    ON PRD.pid = PUR.pid;
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.