php - 使用此内部连接获取数据时遇到问题 (MYSQL/PHP)

标签 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'                    

知道为什么它什么都不返回吗?

最佳答案

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' 

关于php - 使用此内部连接获取数据时遇到问题 (MYSQL/PHP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17025894/

相关文章:

mysql - 从第一条记录返回记录,得到需要返回的记录数

php - 下载 pdf 文件时显示错误(难以理解的符号)

php - 像 Stackoverflow 这样的搜索词结果中的标签定义

PHP/MySQL 查询不起作用?

php - 如何在php mysql中相对于列插入csv数组数据

php - 使用php在mysql中使用一张表从多个表中检索数据

php - Laravel Homestead 路由 : InvalidArgumentException in compiled. php:未找到 View [****]

php - 只显示登录用户的记录

php - GoDaddy 服务器中的请求实体太大

Mysql 查询 Select 语句需要帮助