查询两次执行。 [英] Query Twice Execution.
问题描述
我执行 3个表(收据,项目和付款)的联合查询,其中收据表是主要表格而物品&付款表有收据的外键,没有自己的主键。
I execute a joint query for 3 tables (Receipt, Items and Payment) where Receipt table is primary table While Items & Payment table have foreign keys to Receipt without any Primary Keys of their own.
问题是当我尝试获取数据时,查询执行两次ID,其中我有两行以上在商品和付款表中。
The problem is when I try Fetching data the query executes twice for an ID where I got more then two rows In Items and Payment Tables.
查询是
SELECT   收据。*,项目。*,付款。*
$
FROM      收据INNER JOIN
                   收据上的项目.RID = Items.RID INNER JOIN
                   在Receipt.RID = Payment.RID付款
SELECT Receipt.*, Items.*, Payment.*
FROM Receipt INNER JOIN
Items ON Receipt.RID = Items.RID INNER JOIN
Payment ON Receipt.RID = Payment.RID
在你们问之前;为什么我要单独付款表?
Before You guys ask; why did I separate Payment table?
这是因为可能会因为积分而分期付款。
It's because There might be Installments due to credits.
Habib Ur Rehman
Habib Ur Rehman
推荐答案
可能是因为一对多的关系?
Probably because a relationship one-to many?
对于一张收据 你可以有很多物品和很多款项,对吗?
For one receipt you can have many items and many payments, am I right?
这篇关于查询两次执行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!