简体   繁体   English

引用从第一张表到第二张表的多个行ID,以便每次可以显示第一张表中的所有行

[英]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. 我有2张桌子的账单和备忘录。 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 如果我在2018年9月30日生成备忘录,将显示上面两行的数据

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 如果我生成备忘录,它将显示所有3行的备忘录

How should I keep the reference of bill table in Memos table? 我应该如何在Memos表中保留票据表的参考? should I keep multiple ids in a column? 我应该在一列中保留多个ID吗?

If I understood well, you got an NxM relation between bills and memos. 如果我了解得很好,您在帐单和便笺之间就会有NxM关系。
This is asking for a separate table with 2 foreign keys: one towards the bills and the other towards the memos. 这要求一个单独的表,该表带有2个外键:一个指向帐单,另一个指向备忘录。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在mySql join语句中显示第1个表的所有结果,但仅显示第2个表的第一个结果 - Show all results from 1st table but only 1st result from 2nd table in mySql join statement 如何从第二个表中显示2个不同的ID从第一个表中显示ID - How to show id from 1st table from 2 different ids from 2nd table 如果找不到第二表行,如何显示第一行 - how to show 1st row if 2nd table row is not found 如何从第一个表中返回所有列,而从第二个表中只返回一列 - How to return all columns from 1st table and only 1 column from 2nd table 在2个表中插入值,其中第2个表需要第1个表中的ID - Inserting values in 2 tables where the 2nd table need an ID from the 1st table Codeigniter联接3个表并从第1个表获取数据,其中第1个表与第2个表链接,第2个表与第3个表链接 - codeigniter join 3 tables and get data from 1st table where 1st table is linked with 2nd table and 2nd table is linked with 3rd table Mysql - 如何根据第一个表的 2 列的值显示第二个表中的列? - Mysql - How to display column from 2nd table based on values from 2 columns of 1st table? PHP,mysql和两个数据库 - 使用不同的模式从第一个数据库中的表更新第二个数据库表中的某些行 - PHP, mysql & two databases - updating certain rows in 2nd database table from table in 1st db with different schema 从第2和第3个表中获取第1个表中匹配值的值 - Get the values from 2nd and 3rd table for the matched values in 1st table 是否可以使用PHP PDO从第一张表中的列从第二张表中获取数据? - Is it possible to get data from the 2nd table using column in 1st table using PHP PDO?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM