いくつかのテーブルを結合しようとしていますが、そのうちの1つは同じテーブル上で異なる条件で同じ結合です。私はクエリを出力していますが、統一された行は出力されません。例:必要であればSQL Join Issues
select distinct rfp.id, title, bidtype, rfp.createdon as '#1', s.finishedDt as '#2', c.id as 'Contract #', supp.rfp_contr_supplier_name, es.suppdate as '#3', es2.suppdate as '#4'
from TBL_RFP_Ideas_NEW rfp
left join tbl_rfp_senior s on rfp.id = s.ideaid
left join rfp_contract c on rfp.id = c.ideaid
inner join supplier_view supp on contractnbr = c.id
left join TBL_EmpMaster_Full emp on rfp.sponsor_empid = emp.empid
left join rfp_events e on rfp.id = e.ideaid
left join rfp_events_suppliers es on e.id = es.event_id and e.heading = '4' and e.description = 'Master Agreement effective date'
left join rfp_events_suppliers es2 on e.id = es2.event_id and e.heading = '5' and e.description = 'Master Agreement Rollout date'
where rfp.id = '683311'
group by rfp.id, title, bidtype, rfp.createdon, s.finishedDt, c.id, supp.rfp_contr_supplier_name, es.suppdate, es2.suppdate, e.description
私はテーブルのアーキテクチャ上のいくつかを詳しく説明することができますが、ほとんどその構築された方法を説明した結合します。 Imは、不思議な小さなものを見逃したいと思っています。どんな助けもありがとう!
'distinct'は' rfp.id'だけでなく、行全体で動作することをご存知ですか? –
生データとあなたの結果がどのように見えるかを紹介してください。 –
"group by"を使用する場合は、select文で集計関数(MinやMaxなど)も使用する必要があります。次に、集約関数で使用されているフィールドを「グループ」から削除します。あなたの "グループ"が重複を取り除いているので "DISTINCT"を削除し、 "別個"は冗長です。 –