简体   繁体   中英

MYSQL LEFT JOIN add condition on other table

select principalTable.X, secondTable.ART, secondTable.DETT
from 
(principalTable

left join thirdTable
on on principalTable.X = thirdTable.X

left join secondTable
on principalTable.ART = secondTable.ART and thirdTable.ID = secondTable.ID
)

I've got 3 tables that show some cross data from this query, I need a condition to select only the data from the secondtable that had a common index with the thirdtable , else without the and condition there can be many incorrect results. I've tried the same query with the and applied to principalTable and with that,this work. With the condition applied on the thirdTable it won't work.

Every advice is really appreciated.

try the following query.

select principalTable.X, secondTable.ART, secondTable.DETT 
form principalTable pt,secondTable st,thirdTable tt
where pt.X = tt.X AND pt.ART = st.ART AND st.ID = tt.ID

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