简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM