我需要將兩個表結合成一對多關係,但使用union而不成功。如何將表與1對多關係合併爲1行記錄
我一直在嘗試使用此代碼
select a.equipmentid,
a.codename,
a.name,
a.labelid,
a.ACQUISITIONDATE,
a.description
from TBL_EQUIPMENTMST a where
a.partofid = '57'
union all
select first 1 b.warrantyid, b.startdate, b.enddate from tbl_equipwarranty b
inner join TBL_EQUIPMENTMST c
on b.equipmentid=c.equipmentid
where c.partofid = '57' and b.servicetype='service' order by b.warrantyid desc
union all
select first 1 d.warrantyid, d.startdate, d.enddate from tbl_equipwarranty d
inner join TBL_EQUIPMENTMST e
on d.equipmentid=e.equipmentid
where e.partofid = '57' and d.servicetype='product' order by d.warrantyid desc
誰能幫助我如何產生我的形象我的預期輸出。我正在使用firebird作爲數據庫。如果你在MySQL中有一個解決方案,請告訴我,並試圖找到firebird中的對手。
除了你的第二和第三個查詢的別名看起來完全相同嗎? – FuzzyTree 2014-11-05 04:09:39
抱歉關於相同。我在我的代碼中糾正了它,但它仍然顯示錯誤。 – Mandz 2014-11-05 04:58:03