Convert query in words to relational algebra

relational-algebrarelational-theory

I have a follow-up question to a question I have previously asked on SO.

Instead of the query from my initial question, I want to convert the following into relational algebra:

List the names and phone numbers of the bidders who are not always affected by
double-bidding.

Note: Double-bidding occurs when two different bidders bid the same price on the same exact item.

I have some ideas as to how to proceed:

  • Find all bidders that have double bid (1)
  • Find all bidders who have a bid that isn't double-bidding (2)
  • Find all bidders who have never placed a double-bidding bid (3)

From here, I can get the intersection of (1) and (2) and add (3) to this intersection to get the final answer. (That is my thought process, please correct me if I am wrong)

I have no issues in finding all bidders that have placed a double bid, but the consequent ideas are confusing me quite a bit. This is what I have for "all bidders that have double bid":

  • BID⨝ITEM – (Q1)

  • Q1 ⨝ ρbid→bid', iid→iid', price→price'(Q1) – (Q2)

  • πbidbid != bid'(Q2) ∧ σprice = price'(Q2) ∧ σiid = iid'(Q2)) – (Q3)

How do I use this to find the bidders who are not always affected by double bidding?

By the way, the bolded text is merely for labeling purposes and is not part of the answer.

Best Answer

I think the key point here is the fact that relational algebra eliminates duplicates from its result. So if you use a Project operator to get only iid and price, it will give you the list of bids excluding the duplicate bids. If you subtract this list from the whole bids you will get the bids those are duplicates..

I am not sure though.. Would you please comment on how you feel about this approach?