简体   繁体   中英

Join 3 tables in mysql/php issue

I need to join 3 tables and show all the data :

The following query works fine. Here i have joined 2 tables called "comparitive_statement1" and "comparitive_st_sup". Here the total everything is fine.

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

Now i need to join one more table called "comparitive_st_tech_compliance" with same tender_id and supplier_name. Here when i join my totals are wrong. Placing the query which i have done:

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

What iam doing wrong?

could be the and tc.sup_name=cl.supplier_name part

try

   INNER JOIN comparitive_st_tech_compliance cl ON 
   tci.tender_id=cl.tender_id and tc1.supplier_name=cl.supplier_name 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM