There are products ( Winner - ID_ticket ):

 ID_product Name_product ID_seller Winner
     1 iPhone 2 3
     2 iPhone 2 4

And tickets to them.

 ID_ticket ID_product ID_user
     3 1 1
     4 1 3

Essence of the question:

  • How to change the tables so that the seller has the opportunity to put on sale several copies of the goods, without duplicating the records in the database? When the tickets run out, the Winner field of the product changes to the winner's ID_ticket .
  • For good, only the link table of two fields ID_Product Winner. Only it will be necessary to control that there would be no more records in it than the goods were exhibited - Mike

1 answer 1

If I understand correctly, in your first Winner table is this a link to ID_ticket from the second table? Then why do you duplicate this information in the second table ID_product? If you remove this link from the ticket, then you will be able to link one ticket to several products, without duplicating the records. Or I did not understand your task correctly. In this case, explain in more detail your business process.

  • No, one ticket - one item. The Winner field contains a link to the ID_ticket that won the product. - jaymorrison_by
  • then it is not clear what the problem is? Or do you need to now implement a variant with several winners? - Sergey Vodakov
  • I need to implement an option in which I will not duplicate the same goods from one seller. Those. if the seller has a product in 2 copies, it is necessary that the record of this product is not duplicated. Accordingly, the winner will be 2, 1 for each copy of the goods. - jaymorrison_by
  • If so, then the winner field should be removed from the goods table, and either create a link table, as you were advised, or add an is_winner field to the ticket table with values ​​of 1/0, initially fill there with 0, and then put the winning tickets 1; - Sergey Vodakov
  • This is understandable, but! There may be a limited number of tickets for one item, say 10. And since tickets are linked by ID_product, then if we have 2 copies of the same product, there will be confusion, because ID_product tickets will be the same. - jaymorrison_by