Shathee Ruhunnabi
Shathee Ruhunnabi

Reputation: 103

Referencing multiple row id from 1st table to 2nd table so that it can show all rows from the 1st table every time

I have 2 Tables bills and memos. Every time I generating a Memo I take the number of bills. For Example

Bill Table

+--+----------+------+------------+
|id|product_id|amount|date        |
+--+----------+------+------------+
|01| 001      |   100| 26-09-2018 |
+--+----------+------+------------+
|02| 002      |   100| 28-09-2018 |
+--+----------+------+------------+

If I generate a memo on 30-09-2018 this will show data with the above 2 rows

after generating this if I add another row in bill table, now the table will look like following

+--+----------+------+------------+
|id|product_id|amount|date        |
+--+----------+------+------------+
|01| 001      |   100| 26-09-2018 |
+--+----------+------+------------+
|02| 002      |   100| 28-09-2018 |
+--+----------+------+------------+
|03| 001      |   100| 01-10-2018 |
+--+----------+------+------------+

If I generate a memo this will show memo with all 3 rows

How should I keep the reference of bill table in Memos table? should I keep multiple ids in a column?

Upvotes: 0

Views: 37

Answers (1)

Robert Kock
Robert Kock

Reputation: 6018

If I understood well, you got an NxM relation between bills and memos.
This is asking for a separate table with 2 foreign keys: one towards the bills and the other towards the memos.

Upvotes: 1

Related Questions