我有一个名为relOwner的mySQL数据库,该数据库具有两列:OwnerID,RelationshipOwner
我正在写一个查询与联接引用数据库:
$query = "SELECT b.Contact, b.ContactB, relOwner.OwnerID, relOwner.RelationshipOwner
FROM b
Left JOIN relOwner
ON b.Contact = relOwner.OwnerID
Left JOIN relOwner
ON b.ContactB = relOwner.OwnerID
";
如何在我的php中分别引用RelationshipOwner的值?
$RelationshipOwner = $row['RelationshipOwner'];
$RelationshipOwnerB = $row['RelationshipOwner']; <--- Get value from second JOIN
提前致谢。
似乎在表b
到表上有两个外键列relOwner
(即vizContact
和ContactB
)。
根据Sverri的评论,您将需要为表使用不同的别名(我使用过ro1
和ro2
),并从不同的表列中投影不同的名称(例如,在第二个表列前面加上ro2
):
SELECT b.Contact, b.ContactB, ro1.OwnerID, ro1.RelationshipOwner,
ro2.OwnerID as ro2OwnerId, ro2.RelationshipOwner as ro2RelationshipOwner
FROM b -- Is this table Contact? If so then "Contact b"
Left JOIN relOwner ro1
ON b.Contact = ro1.OwnerID
Left JOIN relOwner ro2
ON b.ContactB = ro2.OwnerID;
您可以参考以下内容:
$row['ro2RelationshipOwner'];
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句