【发布时间】:2016-01-13 16:10:09
【问题描述】:
我正在尝试使用内部联接进行查询,但无法正常工作。它显示多个重复的行。问题是我试图通过使用外键来做到这一点。但我无法解决。 这是第一张桌子
document_details
id inv_no bill_desc bill_amount
1 201501 test bill 1000
2 201501 test bill2 1110
3 201502 C&F Association Fee 50
4 201502 Duty/Vat& Scanning 3620
5 201502 Agent Charges 1750
6 201502 Noc Charges 1775
7 201502 CPA Charges 3572
8 201502 Hi-Star Charges 1800
9 201502 Exam. Miscellanies 5500
10 201502 Import Miscellanies 5000
11 201502 Commission@0.07% 7272
还有第二张桌子
bill_details
id inv_no doc_title doc_desc
1 201501 test test details
2 201501 test2 test2
11 201502
10 201502
9 201502 Doc. Recvd:26.08.15 Delivery:22.09.2015
8 201502 Consignmnt:07Plts Printing Chemical
7 201502 C&F$:129896.67 BD.Tk.10388594.28
6 201502 Inv. No:330955 Date:20.07.2015
5 201502 L/C: 100315050139 Date:07.07.2015
4 201502 BL No:WPG0026958 Date:01.08.2015
3:201502 B/E No:C-992168 Date:17.09.2015
我正在尝试运行以下 sql
$doc_query="SELECT document_details.*,bill_details.* FROM document_details
INNER JOIN bill_details ON document_details.inv_no = bill_details.inv_no
where document_details.inv_no='$inv_id'";
$get_details=mysql_query($doc_query);
while($details_data=mysql_fetch_assoc($get_details))
{}
【问题讨论】:
-
这是一些对@ReneKorss 没有帮助的蹩脚建议。您正在加入一个多对多表,这很明显为什么它会返回多个结果。
-
你必须决定(并解释)你想要的结果!
-
@anwaar_hell 不,没有什么告诉我们这两个 id 是相关的。
-
福哈德。如果你没有用你想要达到的输出的描述来更新你的问题,我会投票结束这个问题,因为不清楚你在问什么,然后继续做其他事情!
-
我越看这个越觉得你要么不了解自己的数据,要么你的数据库设计搞砸了,而且可能两者
标签: php mysql sql inner-join