Skip to content
Advertisement

Assigning multiple rows to a single row of different table SQL

Is it possible to assign several rows to a single row of a different table? Doing purchase order I have a table for Suppliers then under that I have items that are in the different table. Giving me headache for over a week now…

Advertisement

Answer

Not sure what you really want, but my first guess us that you have a many-to-many situation. Am I correct?

If my assumption is correct, the default solution is creating a junction-table. If for instance an Order can contain many Products, and a Product can be associated with many Orders, you usually create something like an OrderDetail table. And that would look something like this:

OrderDetail:
- OrderId
- ProductId
- Quantity 

If you wish, you can even force that the combination of OrderId and ProductId should be unique with a unique key contraint (or unique index, which is usually the same).

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement