无法通过此内部联接获取数据(MYSQL / PHP)

时间:2013-06-10 14:10:42

标签: php mysql

我有3张桌子,我试图从列中返回一个列,这让我哭了,为什么它不起作用:

$projectId = 54971033
$id = 53189015

enter image description here

        SELECT     
            iR.author,
            i.dateCreated,
            i.lastModified,
            i.value,
            u.username
        FROM
            informationRelationships iR
        INNER JOIN
            information i ON
            iR.linkId = i.id
        INNER JOIN
            users u ON
            iR.author = u.id    
        WHERE
            iR.contactRef = '$id' AND
            iR.projectRef = '$projectId' AND
            iR.type = 'Project'                    

为什么它没有返回什么想法?

1 个答案:

答案 0 :(得分:1)

author为零,请尝试使用LEFT JOIN

SELECT     
    iR.author,
    i.dateCreated,
    i.lastModified,
    i.value,
    u.username
FROM
    informationRelationships iR
LEFT JOIN
    information i ON
    iR.linkId = i.id
LEFT JOIN
    users u ON
    iR.author = u.id    
WHERE
    iR.contactRef = '$id' AND
    iR.projectRef = '$projectId' AND
    iR.type = 'Project'