我試圖在我的資料庫中的兩個表之間進行聯合查詢,我寫的陳述句是
SELECT tblMetalsResults.reportno, tblMetalsResults.sampleno, tblMetalsResults.element, tblMetalsResults.ElementResult, tblMetalsResults.ElementRL, tblMetalsResults.ElementAnalyst1, tblMetalsResults.ElementAnalyst2, tblMetalsResults.ElementDate1, tblMetalsResults.ElementDate2, tblLogging.loBattery, tblLogging.loTest
FROM tblLogging INNER JOIN tblMetalsResults ON tblLogging.ReportNo = tblMetalsResults.reportno
WHERE (((tblMetalsResults.reportno)=[forms]![frmlogging]![reportno]))
UNION
SELECT tblHerbicideResults.herbreportno, tblHerbicideResults.sampleno, tblHerbicideResults.24DResults, tblHerbicideResults.D45TPResults, tbllogging.lobattery, tbllogging.lotest
FROM tbllogging INNER JOIN tblHerbicideResults ON tbllogging.Reportno = tblHerbicideResults.herbreportno
WHERE (((tblHerbicideResults.reportno0=[forms]![frmlogging]![reportno]));
有誰知道我做錯了什么?當我嘗試保存時,它說聯合查詢中的語法錯誤。
uj5u.com熱心網友回復:
聯合的兩邊應該有相同的列數和兼容的資料型別。如果您沒有這些列,則可以將這些列創建為null:
SELECT
tblMetalsResults.reportno,
tblMetalsResults.sampleno,
tblMetalsResults.element,
tblMetalsResults.ElementResult,
tblMetalsResults.ElementRL,
tblMetalsResults.ElementAnalyst1,
tblMetalsResults.ElementAnalyst2,
tblMetalsResults.ElementDate1,
tblMetalsResults.ElementDate2,
tblLogging.loBattery,
tblLogging.loTest
FROM tblLogging INNER JOIN tblMetalsResults ON tblLogging.ReportNo = tblMetalsResults.reportno
WHERE (((tblMetalsResults.reportno)=[forms]![frmlogging]![reportno]))
UNION
SELECT
tblHerbicideResults.herbreportno,
tblHerbicideResults.sampleno,
NULL,
tblHerbicideResults.24DResults,
tblHerbicideResults.D45TPResults,
NULL,
NULL,
NULL,
NULL,
tbllogging.lobattery,
tbllogging.lotest
FROM tbllogging INNER JOIN tblHerbicideResults ON tbllogging.Reportno = tblHerbicideResults.herbreportno
WHERE (((tblHerbicideResults.reportno0=[forms]![frmlogging]![reportno]));
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/334860.html
