【发布时间】:2010-01-12 11:55:29
【问题描述】:
大家好,
我有两个表 Incharge 和 property。我的属性表有 1stIncharge、2ndIncharge 和 3rdIncharge 三个字段。 InchargeId 被设置为属性表中所有上述字段的外键..
如何编写一个连接两个表的选择语句..我尝试了一点,但没有结果
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 \\)
Guys 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 的解决方案不是您想要的,请考虑编辑您的问题并提供有关预期结果的示例数据。
标签: mysql join foreign-keys