【发布时间】:2015-11-10 20:55:58
【问题描述】:
所以我很难在 Stack 上找到一个好的答案。我正在寻找将两个表上的信息组合在一起的查询。到目前为止,这就是我所拥有的。实际场景如下:
我将尝试从我的角度进行更多解释以实现这一目标:
我有两张桌子:
Comparitive_st_sup
___________________
id | tender_id | item_name | slno | supplier_name | prod_description
________________________________________________________________________
1 401 Collinear 1 OnlineMetals Description comes here
2 401 Filter 2 OnlineMetals Description comes here
3 401 Antenna 3 OnlineMetals Description Comes here
4 455 Primer 1 KR Electronics Description comes here
5 455 Chock 2 KR Electronics Description comes here
comparitive_st_tech_compliance
_______________________________
id | tender_id | item_name | slno | supplier_name | tech_analyst_comment
__________________________________________________________________________
1 401 Collinear 1 OnlineMetals 90%
2 401 Filter 2 OnlineMetals 25%
3 401 Antenna 3 OnlineMetals 87%
4 455 Primer 1 KR Electronics 64%
5 455 Chick 2 KR Electronics 80%
Now i am expecting a result like:
401 Collinear 1 OnlineMetals Description comes here 90%
401 Filter 2 OnlineMetals Description comes here 25%
401 Antenna 3 OnlineMetals Description comes here 87%
根据选择的tender_id,该值作为查询字符串传递,并且必须相应地显示记录。帮助表示赞赏..
我试过了,但结果不正确:
Select comparitive_st_sup.*,
comparitive_st_sup.tender_id As tender_id1,
comparitive_st_sup.supplier_name As supplier_name1,
comparitive_st_sup.slno As slno1,
comparitive_st_sup.prod_description As prod_description1,
comparitive_st_sup.item_name As item_name1,
comparitive_st_sup.total As total1,
comparitive_st_tech_compliance.tech_analyst_comment
From comparitive_st_tech_compliance
Right Join comparitive_st_sup On comparitive_st_sup.tender_id =
comparitive_st_tech_compliance.tender_id
Where comparitive_st_sup.tender_id = 401
我需要显示 comparitive_st_sup 中的所有字段,并且只显示一个字段 (tech_analyst_comment) 的 where 条件为tender_id。现在记录是重复的。不是显示 3 条记录,而是显示 9 条记录。我有什么错误吗?
【问题讨论】:
-
您确定要使用
RIGHT JOIN吗? -
我可以通过内部连接来实现吗?
-
不,我没有得到想要的输出。 Right Join 和 Inner Join 显示相同的输出