海傢伙,MySQL的加入兩個表來獲取記錄
我有兩個表Incharge和財產。我的物業表有三個字段1stIncharge,2ndIncharge和3rdIncharge。 InchargeId被設置爲在屬性表中的所有上述領域外鍵..
如何編寫連接兩個表中的select語句。我已經盡力了一點,但沒有結果
select P.Id,P.Name,P.1stIncharge,P.2ndIncharge,P.3rdIncharge,I.Id from
Property as P join Incharge as I where (\\How to give condition here \\)
人3場P.1stIncharge,P.2ndIncharge,P.3rdIncharge有外鍵I.Id
編輯:
select P.Id,P.Name,P.1stIncharge,P.2ndIncharge,P.3rdIncharge,I1.Id from
Property as P
inner join Incharge as I1 on I1.Id=P.1stIncharge
inner join Incharge as I2 on I2.Id=P.2ndIncharge
inner join Incharge as I3 on I3.Id=P.3rdIncharge
and this query working
@Saranya:如果Codesleuth的解決方案不是您想要的,請考慮編輯您的問題並提供有關預期結果的示例數據。 – 2010-01-12 12:17:34