海家伙,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