我需要加入3个表并显示所有数据:
以下查询正常。在这里,我加入了两个名为" comparitive_statement1"和" comparitive_st_sup"。一切都很好。
SELECT tc.*,sum(tci.total_inr) as tot1, tci.supplier_name,tci.currency as currency2 FROM comparitive_statement1 tc INNER JOIN comparitive_st_sup tci ON tc.tender_id=tci.tender_id WHERE tc.tender_id='$tender_id' and tc.sup_name=tci.supplier_name GROUP BY tc.sup_name ORDER BY tc.sup_name ASC
现在我需要再加一个名为" comparitive_st_tech_compliance"使用相同的tender_id和supplier_name。在这里,当我加入我的总数是错误的。放置我已完成的查询:
SELECT tc.*, sum(tci.total_inr) as tot1, tci.supplier_name,tci.currency as currency2 FROM comparitive_statement1 tc INNER JOIN comparitive_st_sup tci ON tc.tender_id=tci.tender_id INNER JOIN comparitive_st_tech_compliance cl ON tci.tender_id=cl.tender_id and tc.sup_name=cl.supplier_name WHERE tc.tender_id='$tender_id' GROUP BY tc.sup_name,cl.supplier_name ORDER BY tc.sup_name ASC
我做错了什么?
答案 0 :(得分:0)
可以是and tc.sup_name=cl.supplier_name
部分
尝试
INNER JOIN comparitive_st_tech_compliance cl ON
tci.tender_id=cl.tender_id and tc1.supplier_name=cl.supplier_name