Mysql

Long JOINS Returns No result 所有表都與特定表具有一對多關係

  • August 27, 2012

我有一個主鍵為“RCNO”的表企業。所有其他表通過它的 RCNO 列與 Enterprise 具有一對多的關係。我加入了所有表格,但我什麼也沒得到。下面是查詢。我想附上表格(sql)。我找不到上傳的地方。

SELECT
enterprise.`RCNO` AS enterprise_RCNO,
enterprise.`ADDRESS` AS enterprise_ADDRESS,
enterprise.`NAME` AS enterprise_NAME,
enterprise.`WEBSITE` AS enterprise_WEBSITE,
enterpriseinfo.`ACCTYEAR` AS enterpriseinfo_ACCTYEAR,
enterpriseinfo.`BASISFORCOMPLETION` AS enterpriseinfo_BASISFORCOMPLETION,
enterpriseinfo.`HASEQUITYINVESTMENTABROAD` AS enterpriseinfo_HASEQUITYINVESTMENTABROAD,
enterpriseinfo.`ISPARTOFGROUP` AS enterpriseinfo_ISPARTOFGROUP,
enterpriseinfo.`NOOFSTAFF` AS enterpriseinfo_NOOFSTAFF,
foreignenterprises.`ENTERPRISENAME` AS foreignenterprises_ENTERPRISENAME,
nigerianenterprises.`ENTERPRISENAME` AS nigerianenterprises_ENTERPRISENAME,
principalactivityturnover.`ACCTYEAR` AS principalactivityturnover_ACCTYEAR,
principalactivityturnover.`AREAOFACTIVITY` AS principalactivityturnover_AREAOFACTIVITY,
principalactivityturnover.`PERCENTAGECONTRIBUTION` AS principalactivityturnover_PERCENTAGECONTRIBUTION,
bookvalueofshareholderscapital.`ACCTYEAR` AS bookvalueofshareholderscapital_ACCTYEAR,
bookvalueofshareholderscapital.`BOOKVALUE` AS bookvalueofshareholderscapital_BOOKVALUE,
bookvalueofshareholderscapital.`COUNTRY` AS bookvalueofshareholderscapital_COUNTRY,
bookvalueofshareholderscapital.`NAME` AS bookvalueofshareholderscapital_NAME,
bookvalueofshareholderscapital.`PERCENTAGEOWNERSHIP` AS bookvalueofshareholderscapital_PERCENTAGEOWNERSHIP,
bookvalueofshareholderscapital.`REVALUATION` AS bookvalueofshareholderscapital_REVALUATION,
bookvalueofshareholderscapital.`SHARESPURCHASED` AS bookvalueofshareholderscapital_SHARESPURCHASED,
bookvalueofshareholderscapital.`SHARESSOLD` AS bookvalueofshareholderscapital_SHARESSOLD,
inwarddirectinvestment.`ACCTYEAR` AS inwarddirectinvestment_ACCTYEAR,
inwarddirectinvestment.`BOOKSHARECAPITAL` AS inwarddirectinvestment_BOOKSHARECAPITAL,
inwarddirectinvestment.`COUNTRY` AS inwarddirectinvestment_COUNTRY,
inwarddirectinvestment.`NAME` AS inwarddirectinvestment_NAME,
inwarddirectinvestment.`PURCHASEDSHAREFROMINVESTOR` AS inwarddirectinvestment_PURCHASEDSHAREFROMINVESTOR,
inwarddirectinvestment.`SALESOFSHARETOINVESTOR` AS inwarddirectinvestment_SALESOFSHARETOINVESTOR,
inwarddirectinvestment.`SHARECAPITALPERCENTAGE` AS inwarddirectinvestment_SHARECAPITALPERCENTAGE,
inwarddirectinvestmentsubsidiary.`ACCTYEAR` AS inwarddirectinvestmentsubsidiary_ACCTYEAR,
inwarddirectinvestmentsubsidiary.`BOOKSHARECAPITAL` AS inwarddirectinvestmentsubsidiary_BOOKSHARECAPITAL,
inwarddirectinvestmentsubsidiary.`COUNTRY` AS inwarddirectinvestmentsubsidiary_COUNTRY,
inwarddirectinvestmentsubsidiary.`NAME` AS inwarddirectinvestmentsubsidiary_NAME,
inwarddirectinvestmentsubsidiary.`PURCHASEDSHAREFROMINVESTOR` AS inwarddirectinvestmentsubsidiary_PURCHASEDSHAREFROMINVESTOR,
inwarddirectinvestmentsubsidiary.`SALESOFSHARETOINVESTOR` AS inwarddirectinvestmentsubsidiary_SALESOFSHARETOINVESTOR,
inwarddirectinvestmentsubsidiary.`SHARECAPITALPERCENTAGE` AS inwarddirectinvestmentsubsidiary_SHARECAPITALPERCENTAGE,
inwarddirectinvestmentsubsidiaryp.`ACCTYEAR` AS inwarddirectinvestmentsubsidiaryp_ACCTYEAR,
inwarddirectinvestmentsubsidiaryp.`BOOKSHARECAPITAL` AS inwarddirectinvestmentsubsidiaryp_BOOKSHARECAPITAL,
inwarddirectinvestmentsubsidiaryp.`COUNTRY` AS inwarddirectinvestmentsubsidiaryp_COUNTRY,
inwarddirectinvestmentsubsidiaryp.`NAME` AS inwarddirectinvestmentsubsidiaryp_NAME,
inwarddirectinvestmentsubsidiaryp.`PURCHASEDSHAREFROMINVESTOR` AS inwarddirectinvestmentsubsidiaryp_PURCHASEDSHAREFROMINVESTOR,
inwarddirectinvestmentsubsidiaryp.`SALESOFSHARETOINVESTOR` AS inwarddirectinvestmentsubsidiaryp_SALESOFSHARETOINVESTOR,
inwarddirectinvestmentsubsidiaryp.`SHARECAPITALPERCENTAGE` AS inwarddirectinvestmentsubsidiaryp_SHARECAPITALPERCENTAGE,
inwardportfolioinvestmentsubsidiary.`ACCTYEAR` AS inwardportfolioinvestmentsubsidiary_ACCTYEAR,
inwardportfolioinvestmentsubsidiary.`COUNTRY` AS inwardportfolioinvestmentsubsidiary_COUNTRY,
inwardportfolioinvestmentsubsidiary.`MARKETVALUE` AS inwardportfolioinvestmentsubsidiary_MARKETVALUE,
inwardportfolioinvestmentsubsidiary.`NAME` AS inwardportfolioinvestmentsubsidiary_NAME,
inwardportfolioinvestmentsubsidiary.`PURCHASEOFSHARES` AS inwardportfolioinvestmentsubsidiary_PURCHASEOFSHARES,
inwardportfolioinvestmentsubsidiary.`SALESOFSHARES` AS inwardportfolioinvestmentsubsidiary_SALESOFSHARES,
inwardportfolioinvestmentsubsidiary.`SHARECAPITALPERCENTAGE` AS inwardportfolioinvestmentsubsidiary_SHARECAPITALPERCENTAGE,
inwardportfolioinvestmentsubsidiaryp.`ACCTYEAR` AS inwardportfolioinvestmentsubsidiaryp_ACCTYEAR,
inwardportfolioinvestmentsubsidiaryp.`COUNTRY` AS inwardportfolioinvestmentsubsidiaryp_COUNTRY,
inwardportfolioinvestmentsubsidiaryp.`MARKETVALUE` AS inwardportfolioinvestmentsubsidiaryp_MARKETVALUE,
inwardportfolioinvestmentsubsidiaryp.`NAME` AS inwardportfolioinvestmentsubsidiaryp_NAME,
inwardportfolioinvestmentsubsidiaryp.`PURCHASEOFSHARES` AS inwardportfolioinvestmentsubsidiaryp_PURCHASEOFSHARES,
inwardportfolioinvestmentsubsidiaryp.`SALESOFSHARES` AS inwardportfolioinvestmentsubsidiaryp_SALESOFSHARES,
inwardportfolioinvestmentsubsidiaryp.`SHARECAPITALPERCENTAGE` AS inwardportfolioinvestmentsubsidiaryp_SHARECAPITALPERCENTAGE,
externaldebtnonresident.`ACCTYEAR` AS externaldebtnonresident_ACCTYEAR,
externaldebtnonresident.`INTERESTPAYABLE` AS externaldebtnonresident_INTERESTPAYABLE,
externaldebtnonresident.`NETTRASACTIONS` AS externaldebtnonresident_NETTRASACTIONS,
externaldebtnonresident.`OTHERCHARGES` AS externaldebtnonresident_OTHERCHARGES,
externaldebtnonresident.`STOCKOFDEBT` AS externaldebtnonresident_STOCKOFDEBT,
externaldebtnonresidentsubsidiary.`ACCTYEAR` AS externaldebtnonresidentsubsidiary_ACCTYEAR,
externaldebtnonresidentsubsidiary.`INTERESTPAYABLE` AS externaldebtnonresidentsubsidiary_INTERESTPAYABLE,
externaldebtnonresidentsubsidiary.`NETTRASACTIONS` AS externaldebtnonresidentsubsidiary_NETTRASACTIONS,
externaldebtnonresidentsubsidiary.`OTHERCHARGES` AS externaldebtnonresidentsubsidiary_OTHERCHARGES,
externaldebtnonresidentsubsidiary.`STOCKOFDEBT` AS externaldebtnonresidentsubsidiary_STOCKOFDEBT,
externaldebtnonresidentsubsidiaryp.`ACCTYEAR` AS externaldebtnonresidentsubsidiaryp_ACCTYEAR,
externaldebtnonresidentsubsidiaryp.`INTERESTPAYABLE` AS externaldebtnonresidentsubsidiaryp_INTERESTPAYABLE,
externaldebtnonresidentsubsidiaryp.`NETTRASACTIONS` AS externaldebtnonresidentsubsidiaryp_NETTRASACTIONS,
externaldebtnonresidentsubsidiaryp.`OTHERCHARGES` AS externaldebtnonresidentsubsidiaryp_OTHERCHARGES,
externaldebtnonresidentsubsidiaryp.`STOCKOFDEBT` AS externaldebtnonresidentsubsidiaryp_STOCKOFDEBT,
externaldebtunrelated.`ACCTYEAR` AS externaldebtunrelated_ACCTYEAR,
externaldebtunrelated.`CLOSINGBALANCE` AS externaldebtunrelated_CLOSINGBALANCE,
externaldebtunrelated.`DEBTINSTRUMENT` AS externaldebtunrelated_DEBTINSTRUMENT,
externaldebtunrelated.`RECIEPTS` AS externaldebtunrelated_RECIEPTS,
externaldebtunrelated.`REPAYMENTS` AS externaldebtunrelated_REPAYMENTS,
externaldebtunrelated.`REVALUATIONS` AS externaldebtunrelated_REVALUATIONS,
externaldebtunrelated.`INTERESTPAYABLE` AS externaldebtunrelated_INTERESTPAYABLE,
externaldebtliabilitiescountry.`ACCTYEAR` AS externaldebtliabilitiescountry_ACCTYEAR,
externaldebtliabilitiescountry.`COUNTRY` AS externaldebtliabilitiescountry_COUNTRY,
externaldebtliabilitiescountry.`DEBTAMOUNT` AS externaldebtliabilitiescountry_DEBTAMOUNT,
externaldebtliabilitiescountry.`DEBTINSTRUMENT` AS externaldebtliabilitiescountry_DEBTINSTRUMENT,
otherincomefromnonresidents.`ACCTYEAR` AS otherincomefromnonresidents_ACCTYEAR,
otherincomefromnonresidents.`INCOMEITEM` AS otherincomefromnonresidents_INCOMEITEM,
otherincomefromnonresidents.`INCOMEVALUE` AS otherincomefromnonresidents_INCOMEVALUE,
shareholderscapitalofsubsidiary.`ACCTYEAR` AS shareholderscapitalofsubsidiary_ACCTYEAR,
shareholderscapitalofsubsidiary.`BOOKVALUEOFSHAREHOLDERS` AS shareholderscapitalofsubsidiary_BOOKVALUEOFSHAREHOLDERS,
shareholderscapitalofsubsidiary.`CHANGEINPAIDUPSHARECAPITAL` AS shareholderscapitalofsubsidiary_CHANGEINPAIDUPSHARECAPITAL,
shareholderscapitalofsubsidiary.`CHANGEINRETAINEDEARNING` AS shareholderscapitalofsubsidiary_CHANGEINRETAINEDEARNING,
shareholderscapitalofsubsidiary.`COUNTRY` AS shareholderscapitalofsubsidiary_COUNTRY,
shareholderscapitalofsubsidiary.`NAME` AS shareholderscapitalofsubsidiary_NAME,
shareholderscapitalofsubsidiary.`REVALUATION` AS shareholderscapitalofsubsidiary_REVALUATION,
enterpriseinvestments.`ACCTYEAR` AS enterpriseinvestments_ACCTYEAR,
enterpriseinvestments.`INVESTMENTAMOUNT` AS enterpriseinvestments_INVESTMENTAMOUNT,
enterpriseinvestments.`INVESTMENTITEM` AS enterpriseinvestments_INVESTMENTITEM,
subsidiaryincomeaccount.`ACCTYEAR` AS subsidiaryincomeaccount_ACCTYEAR,
subsidiaryincomeaccount.`DIVIDENSANDPROFITSPAID` AS subsidiaryincomeaccount_DIVIDENSANDPROFITSPAID,
subsidiaryincomeaccount.`ENTERPRISENAME` AS subsidiaryincomeaccount_ENTERPRISENAME,
subsidiaryincomeaccount.`NETINCOMEAFTERTAX` AS subsidiaryincomeaccount_NETINCOMEAFTERTAX,
subsidiaryincomeaccount.`RETAINEDEARNING` AS subsidiaryincomeaccount_RETAINEDEARNING,
equityclaimsofparent.`COUNTRY` AS equityclaimsofparent_COUNTRY,
equityclaimsofparent.`EQUITYVALUEHELD` AS equityclaimsofparent_EQUITYVALUEHELD,
equityclaimsofparent.`NAME` AS equityclaimsofparent_NAME,
equityclaimsofparent.`NETPURCHASES` AS equityclaimsofparent_NETPURCHASES,
equityclaimsofparent.`NETSALES` AS equityclaimsofparent_NETSALES,
equityclaimsofparent.`OTHERCHARGESREVALUATION` AS equityclaimsofparent_OTHERCHARGESREVALUATION,
equityclaimsofparent.`PERCENTAGESHARES` AS equityclaimsofparent_PERCENTAGESHARES,
equityclaimsofparent.`ACCTYEAR` AS equityclaimsofparent_ACCTYEAR,
equityclaimsofparentsub.`COUNTRY` AS equityclaimsofparentsub_COUNTRY,
equityclaimsofparentsub.`EQUITYVALUEHELD` AS equityclaimsofparentsub_EQUITYVALUEHELD,
equityclaimsofparentsub.`NAME` AS equityclaimsofparentsub_NAME,
equityclaimsofparentsub.`NETPURCHASES` AS equityclaimsofparentsub_NETPURCHASES,
equityclaimsofparentsub.`NETSALES` AS equityclaimsofparentsub_NETSALES,
equityclaimsofparentsub.`OTHERCHARGESREVALUATION` AS equityclaimsofparentsub_OTHERCHARGESREVALUATION,
equityclaimsofparentsub.`PERCENTAGESHARES` AS equityclaimsofparentsub_PERCENTAGESHARES,
equityclaimsofparentsub.`ACCTYEAR` AS equityclaimsofparentsub_ACCTYEAR,
equityclaimsofparentsubp.`COUNTRY` AS equityclaimsofparentsubp_COUNTRY,
equityclaimsofparentsubp.`EQUITYVALUEHELD` AS equityclaimsofparentsubp_EQUITYVALUEHELD,
equityclaimsofparentsubp.`NAME` AS equityclaimsofparentsubp_NAME,
equityclaimsofparentsubp.`NETPURCHASES` AS equityclaimsofparentsubp_NETPURCHASES,
equityclaimsofparentsubp.`NETSALES` AS equityclaimsofparentsubp_NETSALES,
equityclaimsofparentsubp.`OTHERCHARGESREVALUATION` AS equityclaimsofparentsubp_OTHERCHARGESREVALUATION,
equityclaimsofparentsubp.`PERCENTAGESHARES` AS equityclaimsofparentsubp_PERCENTAGESHARES,
equityclaimsofparentsubp.`ACCTYEAR` AS equityclaimsofparentsubp_ACCTYEAR,
externallendingtosubsidiary.`ACCTYEAR` AS externallendingtosubsidiary_ACCTYEAR,
externallendingtosubsidiary.`AGGOFEXTERNALLENDING` AS externallendingtosubsidiary_AGGOFEXTERNALLENDING,
externallendingtosubsidiary.`ENTITYNAME` AS externallendingtosubsidiary_ENTITYNAME,
externallendingtosubsidiary.`INTERESTRECIEVABLE` AS externallendingtosubsidiary_INTERESTRECIEVABLE,
externallendingtosubsidiary.`NETLENDING` AS externallendingtosubsidiary_NETLENDING,
externallendingtosubsidiary.`OTHERCHANGESANDREVALUATION` AS externallendingtosubsidiary_OTHERCHANGESANDREVALUATION,
externallendingrelatedparent.`ACCTYEAR` AS externallendingrelatedparent_ACCTYEAR,
externallendingrelatedparent.`AGGEXTERNALLENDING` AS externallendingrelatedparent_AGGEXTERNALLENDING,
externallendingrelatedparent.`INTERESTRECIEVABLE` AS externallendingrelatedparent_INTERESTRECIEVABLE,
externallendingrelatedparent.`NETLENDING` AS externallendingrelatedparent_NETLENDING,
externallendingrelatedparent.`REVALUATIONS` AS externallendingrelatedparent_REVALUATIONS,
externallendingrelatedsubparent.`ACCTYEAR` AS externallendingrelatedsubparent_ACCTYEAR,
externallendingrelatedsubparent.`AGGEXTERNALLENDING` AS externallendingrelatedsubparent_AGGEXTERNALLENDING,
externallendingrelatedsubparent.`INTERESTRECIEVABLE` AS externallendingrelatedsubparent_INTERESTRECIEVABLE,
externallendingrelatedsubparent.`NETLENDING` AS externallendingrelatedsubparent_NETLENDING,
externallendingrelatedsubparent.`REVALUATIONS` AS externallendingrelatedsubparent_REVALUATIONS,
debtinstrumentsheldunrelated.`ACCTYEAR` AS debtinstrumentsheldunrelated_ACCTYEAR,
debtinstrumentsheldunrelated.`CLOSINGBALANCE` AS debtinstrumentsheldunrelated_CLOSINGBALANCE,
debtinstrumentsheldunrelated.`DEBTINSTRUMENT` AS debtinstrumentsheldunrelated_DEBTINSTRUMENT,
debtinstrumentsheldunrelated.`INTERESTRECIEVABLE` AS debtinstrumentsheldunrelated_INTERESTRECIEVABLE,
debtinstrumentsheldunrelated.`OPENINGBALANCE` AS debtinstrumentsheldunrelated_OPENINGBALANCE,
debtinstrumentsheldunrelated.`PRINCIPALREPAYMENT` AS debtinstrumentsheldunrelated_PRINCIPALREPAYMENT,
debtinstrumentsheldunrelated.`PURCHASE` AS debtinstrumentsheldunrelated_PURCHASE,
debtinstrumentsheldunrelated.`REVALUATION` AS debtinstrumentsheldunrelated_REVALUATION,
debtinstrumenturcountry.`ACCTYEAR` AS debtinstrumenturcountry_ACCTYEAR,
debtinstrumenturcountry.`DEBTAMOUNT` AS debtinstrumenturcountry_DEBTAMOUNT,
debtinstrumenturcountry.`DEBTINSTRUMENT` AS debtinstrumenturcountry_DEBTINSTRUMENT,
debtinstrumenturcountry.`DEBTORCOUNTRY` AS debtinstrumenturcountry_DEBTORCOUNTRY,
otherexpenditurenr.`ACCTYEAR` AS otherexpenditurenr_ACCTYEAR,
otherexpenditurenr.`EXPENSEITEM` AS otherexpenditurenr_EXPENSEITEM,
otherexpenditurenr.`EXPENSEVALUE` AS otherexpenditurenr_EXPENSEVALUE,
depositwithnonresidentbanks.`ACCTYEAR` AS depositwithnonresidentbanks_ACCTYEAR,
depositwithnonresidentbanks.`BANKNAME` AS depositwithnonresidentbanks_BANKNAME,
depositwithnonresidentbanks.`CHANGESDUETOEXCHANGE` AS depositwithnonresidentbanks_CHANGESDUETOEXCHANGE,
depositwithnonresidentbanks.`CURRENTOUTSTANDINGBALANCE` AS depositwithnonresidentbanks_CURRENTOUTSTANDINGBALANCE,
depositwithnonresidentbanks.`TRANSACTIONSTHISYEAR` AS depositwithnonresidentbanks_TRANSACTIONSTHISYEAR,
finderivativecontractwithnr.`ACCTYEAR` AS finderivativecontractwithnr_ACCTYEAR,
finderivativecontractwithnr.`CASHRECIEPTSANDDERIVATIVEPAYMENT` AS finderivativecontractwithnr_CASHRECIEPTSANDDERIVATIVEPAYMENT,
finderivativecontractwithnr.`NONRESIDENTNAME` AS finderivativecontractwithnr_NONRESIDENTNAME,
finderivativecontractwithnr.`OUTSTANDINGMARKETPOSITION` AS finderivativecontractwithnr_OUTSTANDINGMARKETPOSITION,
foriegngovtdebtsecuritycountry.`ACCTYEAR` AS foriegngovtdebtsecuritycountry_ACCTYEAR,
foriegngovtdebtsecuritycountry.`CHANGESINVALUEDUETOEXCHANGE` AS foriegngovtdebtsecuritycountry_CHANGESINVALUEDUETOEXCHANGE,
foriegngovtdebtsecuritycountry.`INTERESTRECIEVABLE` AS foriegngovtdebtsecuritycountry_INTERESTRECIEVABLE,
foriegngovtdebtsecuritycountry.`NAME` AS foriegngovtdebtsecuritycountry_NAME,
foriegngovtdebtsecuritycountry.`OTHERCHANGESINCLUDINGREVALUATION` AS foriegngovtdebtsecuritycountry_OTHERCHANGESINCLUDINGREVALUATION,
foriegngovtdebtsecuritycountry.`OUTSTANDINGMARKETVALUE` AS foriegngovtdebtsecuritycountry_OUTSTANDINGMARKETVALUE,
dividendearningsprofit.`ACCTYEAR` AS dividendearningsprofit_ACCTYEAR,
    dividendearningsprofit.`DIVIDENDSPAID` AS dividendearningsprofit_DIVIDENDSPAID,
    dividendearningsprofit.`INTERESTPAID` AS dividendearningsprofit_INTERESTPAID,
    dividendearningsprofit.`INTERESTRECIEVED` AS dividendearningsprofit_INTERESTRECIEVED,
    dividendearningsprofit.`NETINCOMEAFTERTAX` AS dividendearningsprofit_NETINCOMEAFTERTAX,
    dividendearningsprofit.`REALISEDHOLDINGS` AS dividendearningsprofit_REALISEDHOLDINGS,
    dividendearningsprofit.`RETAINEDEARNING` AS dividendearningsprofit_RETAINEDEARNING
FROM
`enterprise` enterprise INNER JOIN `enterpriseinfo` enterpriseinfo ON enterprise.`RCNO` = enterpriseinfo.`RCNO`
INNER JOIN `foreignenterprises` foreignenterprises ON enterprise.`RCNO` = foreignenterprises.`RCNO`
INNER JOIN `nigerianenterprises` nigerianenterprises ON enterprise.`RCNO` = nigerianenterprises.`RCNO`
INNER JOIN `principalactivityturnover` principalactivityturnover ON enterprise.`RCNO` = principalactivityturnover.`RCNO`
INNER JOIN `bookvalueofshareholderscapital` bookvalueofshareholderscapital ON enterprise.`RCNO` = bookvalueofshareholderscapital.`RCNO`
INNER JOIN `inwarddirectinvestment` inwarddirectinvestment ON enterprise.`RCNO` = inwarddirectinvestment.`RCNO`
INNER JOIN `inwarddirectinvestmentsubsidiary` inwarddirectinvestmentsubsidiary ON enterprise.`RCNO` = inwarddirectinvestmentsubsidiary.`RCNO`
INNER JOIN `inwarddirectinvestmentsubsidiaryp` inwarddirectinvestmentsubsidiaryp ON enterprise.`RCNO` = inwarddirectinvestmentsubsidiaryp.`RCNO`
INNER JOIN `inwardportfolioinvestmentsubsidiary` inwardportfolioinvestmentsubsidiary ON enterprise.`RCNO` = inwardportfolioinvestmentsubsidiary.`RCNO`
INNER JOIN `inwardportfolioinvestmentsubsidiaryp` inwardportfolioinvestmentsubsidiaryp ON enterprise.`RCNO` = inwardportfolioinvestmentsubsidiaryp.`RCNO`
INNER JOIN `externaldebtnonresident` externaldebtnonresident ON enterprise.`RCNO` = externaldebtnonresident.`RCNO`
INNER JOIN `externaldebtnonresidentsubsidiary` externaldebtnonresidentsubsidiary ON enterprise.`RCNO` = externaldebtnonresidentsubsidiary.`RCNO`
INNER JOIN `externaldebtnonresidentsubsidiaryp` externaldebtnonresidentsubsidiaryp ON enterprise.`RCNO` = externaldebtnonresidentsubsidiaryp.`RCNO`
INNER JOIN `externaldebtunrelated` externaldebtunrelated ON enterprise.`RCNO` = externaldebtunrelated.`RCNO`
INNER JOIN `externaldebtliabilitiescountry` externaldebtliabilitiescountry ON enterprise.`RCNO` = externaldebtliabilitiescountry.`RCNO`
INNER JOIN `otherincomefromnonresidents` otherincomefromnonresidents ON enterprise.`RCNO` = otherincomefromnonresidents.`RCNO`
INNER JOIN `shareholderscapitalofsubsidiary` shareholderscapitalofsubsidiary ON enterprise.`RCNO` = shareholderscapitalofsubsidiary.`RCNO`
INNER JOIN `enterpriseinvestments` enterpriseinvestments ON enterprise.`RCNO` = enterpriseinvestments.`RCNO`
INNER JOIN `subsidiaryincomeaccount` subsidiaryincomeaccount ON enterprise.`RCNO` = subsidiaryincomeaccount.`RCNO`
INNER JOIN `equityclaimsofparent` equityclaimsofparent ON enterprise.`RCNO` = equityclaimsofparent.`RCNO`
INNER JOIN `equityclaimsofparentsub` equityclaimsofparentsub ON enterprise.`RCNO` = equityclaimsofparentsub.`RCNO`
INNER JOIN `equityclaimsofparentsubp` equityclaimsofparentsubp ON enterprise.`RCNO` = equityclaimsofparentsubp.`RCNO`
INNER JOIN `externallendingtosubsidiary` externallendingtosubsidiary ON enterprise.`RCNO` = externallendingtosubsidiary.`RCNO`
INNER JOIN `externallendingrelatedparent` externallendingrelatedparent ON enterprise.`RCNO` = externallendingrelatedparent.`RCNO`
INNER JOIN `externallendingrelatedsubparent` externallendingrelatedsubparent ON enterprise.`RCNO` = externallendingrelatedsubparent.`RCNO`
INNER JOIN `debtinstrumentsheldunrelated` debtinstrumentsheldunrelated ON enterprise.`RCNO` = debtinstrumentsheldunrelated.`RCNO`
INNER JOIN `debtinstrumenturcountry` debtinstrumenturcountry ON enterprise.`RCNO` = debtinstrumenturcountry.`RCNO`
INNER JOIN `otherexpenditurenr` otherexpenditurenr ON enterprise.`RCNO` = otherexpenditurenr.`RCNO`
INNER JOIN `depositwithnonresidentbanks` depositwithnonresidentbanks ON enterprise.`RCNO` = depositwithnonresidentbanks.`RCNO`
INNER JOIN `finderivativecontractwithnr` finderivativecontractwithnr ON enterprise.`RCNO` = finderivativecontractwithnr.`RCNO`
INNER JOIN `foriegngovtdebtsecuritycountry` foriegngovtdebtsecuritycountry ON enterprise.`RCNO` = foriegngovtdebtsecuritycountry.`RCNO`,
`dividendearningsprofit` dividendearningsprofit
WHERE
    enterprise.RCNO = 'RC 10000'

當您建構複雜的查詢時,您應該分階段建構它們,並隨時檢查結果,而不是建構一個完整的龐大查詢然後嘗試找出問題所在。這就是我所做的。

首先,我在一個單獨的行上列出我想要的所有列,並註釋掉除第一個表中的列之外的所有列。然後我在第一個表上添加 from 子句和任何 where 條件。我注意到返回了多少條記錄。然後我一次添加每個表並再次檢查結果。當數字意外地跳得非常高或意外地下降時,我尤其擔心。

在數字跳得很高的情況下,您可能存在需要進一步定義的一對多關係。如果您從表中獲取的一個或多個欄位幾乎總是相同的,則尤其如此。您可能需要派生表或特定的 where 條件來解析。你甚至可能想做一些聚合。現在我並不是說如果記錄數上升總是不好的,只有當它們上升時你沒想到它們或結果集看起來可疑時。

在第二種情況下,您通常有一個內連接,您需要一個左連接。記錄數減少是因為您在連接表中沒有匹配的記錄。我經常用左連接檢查每個內連接,以確保返回相同數量的記錄。如果是,那麼內部聯接是合適的,如果不是,那麼我需要決定它是過濾我應該過濾的記錄,還是我需要一個左連接。

當我不確定為什麼記錄計數與預期不一致時,我使用 select *(臨時)來查看所有數據,以便確定數據關閉的原因。當我看到所有數據時,我幾乎總能說出問題所在。永遠不要在這樣的多連接查詢中使用 select * ,否則您將返回比您需要的更多的數據,從而減慢查詢速度,因為至少重複連接欄位(另外,您確實不太可能需要 20 中的每個欄位加入!)。

要找到您的問題,您將不得不重複此過程。從 from 子句及其上的 where 條件開始,然後添加表,直到找到導致查詢消除所有記錄的表。不要停止第一次查找,在這樣的長查詢中可能會遇到多個問題。

這不起作用的原因是一個或多個表為空或 FK 列上有 NULL。

由於 INNER JOIN 要求在每個連接的表中至少存在一個符合關係的行,因此只需要一個不滿足此要求的表對所有語句返回 0 行。

解決方案是從連接中刪除表,直到罪魁禍首出現。(或使用左連接)…

引用自:https://dba.stackexchange.com/questions/20937