[英]Left join - joined tables double results
this is my query with two left joins (tried to join bcompany - main table WITH bpoint, bug): 这是我的查询,有两个左联接(试图联接bcompany-带bpoint,bug的主表):
SELECT cName, sName, uNaslov FROM bcompany c LEFT JOIN bpoint p ON c.companyID = p.companyID LEFT JOIN bug b ON c.companyID = b.companyID WHERE c.companyID='$cID'
First table bcompany
is a main one, and there is always exactly one result row. 第一个表bcompany
是一个主表,并且始终只有一个结果行。
Both tables bpoint
and bug
relate to bcompany
via the companyID
column. 这两个表bpoint
和bug
涉及bcompany
经由companyID
柱。 These two tables will not necessarily have any records. 这两个表不一定有任何记录。
My problem are doubled results of those two joined tables. 我的问题是这两个联接表的结果翻了一番。 I can understand multiple results for the main table, but not for the joined two. 我可以理解主表的多个结果,但不能理解两个联合表的结果。
Table structure: 表结构:
bcompany: 公司:
companyID | cName |
---------------------------------
1 | Mladi Tehnik d.o.o. |
bpoint: bpoint:
pointID | sName | companyID |
-------------------------------------------
1 | Mladi Tehnik | 1 |
2 | Pizzerija 5ka | 1 |
3 | Gostilna Kekec | 1 |
4 | Blejski tehnik | 1 |
bug: 错误:
bugID | uNaslov | companyID |
-----------------------------------
1 | Testna 1 | 1 |
2 | Testna 2 | 1 |
3 | Mickino kolo | 1 |
Results example: 结果示例:
bcompany:
Mladi Tehnik d.o.o.
Mladi Tehnik d.o.o.
Mladi Tehnik d.o.o.
Mladi Tehnik d.o.o.
Mladi Tehnik d.o.o.
Mladi Tehnik d.o.o.
Mladi Tehnik d.o.o.
Mladi Tehnik d.o.o.
Mladi Tehnik d.o.o.
Mladi Tehnik d.o.o.
Mladi Tehnik d.o.o.
Mladi Tehnik d.o.o.
bpoint:
Mladi Tehnik
Mladi Tehnik
Mladi Tehnik
Pizzerija 5ka
Pizzerija 5ka
Pizzerija 5ka
Gostilna Kekec
Gostilna Kekec
Gostilna Kekec
Blejski Tehnik
Blejski Tehnik
Blejski Tehnik
bug:
Testna 1
Testna 2
Mickino kolo
Testna 1
Testna 2
Mickino kolo
Testna 1
Testna 2
Mickino kolo
Testna 1
Testna 2
Mickino kolo
The results i want (every existing result only once): 我想要的结果(每个现有结果仅一次):
bcompany:
Mladi Tehnik d.o.o.
bpoint:
Mladi Tehnik
Pizzerija 5ka
Gostilna Kekec
Blejski Tehnik
bug:
Testna 1
Testna 2
Mickino kolo
The result is ok. 结果还可以。 If there were only one entry in the bpoint
column the result would be inconsistent because there is one "Mladi Tehnik doo" with "Mladi Tehnik" and the exact same one without a bpoint
entry. 如果bpoint
列中只有一个条目,则结果将不一致,因为存在一个“ Mladi Tehnik doo”和“ Mladi Tehnik” ,而一个完全相同而没有bpoint
条目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.