MySQL查询LEFT JOIN缺失值

时间:2014-12-10 04:06:52

标签: mysql

我的查询由于某种原因遗漏了大多数值的ISRC代码。包含ISRC CODE的两个记录是由于连接而出现的记录。这些查询的$artist_name = "Brady Hartvigsen"

$result = mysqli_query($con,"SELECT * 
        FROM isrc_codes i
        LEFT JOIN contributors c on i.ISRC_CODE = c.ISRC_CODE
        WHERE i.TRACK_ARTIST = '" . $artist_name . "' 
        OR c.CONTRIBUTOR = '" . $artist_name . "' 
        ORDER BY i.ISRC_CODE DESC");

这给了我这个输出

ISRC代码/歌曲/艺术​​家/贡献者/百分比


QMJND1400003让我们跳起Shane Bingham Brady Hartvigsen(10%)40%


QMJND1400002国王之城布雷迪哈特维格森(50%)0%


Scarlet Skies Brady Hartvigsen 50%


搁浅Brady Hartvigsen 50%


使用此代码,我可以使用ISRC CODEs输出,但不会在该人是其贡献者的轨道上输出

$result = mysqli_query($con,"SELECT * 
        FROM isrc_codes 
        WHERE TRACK_ARTIST = '" . $artist_name . "' 
        OR CONTRIBUTOR = '" . $artist_name . "' 
        ORDER BY ISRC_CODE DESC");

GBSMU1274772 Scarlet Skies Brady Hartvigsen 50%


GBSMU1274771搁浅的Brady Hartvigsen 50%



所以我需要的是这个

QMJND1400003让我们跳起Shane Bingham Brady Hartvigsen(10%)40%


QMJND1400002国王之城布雷迪哈特维格森(50%)0%


GBSMU1274772 Scarlet Skies Brady Hartvigsen 50%


GBSMU1274771搁浅的Brady Hartvigsen 50%

ISRC代码表 ISRC Code Table

贡献者表

Contributor Table

出于某种原因,它将ISRC代码放在[0]中但不放在[ISRC_CODE]

Array
(
    [0] => GBSMU1094901
    [ISRC_CODE] => 
    [1] => Take My Heart
    [TRACK_TITLE] => Take My Heart
    [2] => 
    [TRACK_SUBTITLE] => 
    [3] => Brady Hartvigsen
    [TRACK_ARTIST] => Brady Hartvigsen
    [4] => 50
    [CONTRACT_PERCENTAGE] => 50
    [5] => 
    [id] => 
    [6] => 
    [7] => 
    [contributor] => 
    [8] => 
    [contributor_percentage] => 
)

0 个答案:

没有答案