1

phpmyadmin 中的以下查询根据我的需要返回具有三个不同条目 ID 的三列 (entry_id)。

SELECT sub_1.entry_id, sub_2.entry_id, sub_3.entry_id
FROM exp_judging_portfolios AS jud
LEFT JOIN exp_submissions AS sub_1 ON sub_1.id = jud.rel_id_1
LEFT JOIN exp_submissions AS sub_2 ON sub_2.id = jud.rel_id_2
LEFT JOIN exp_submissions AS sub_3 ON sub_3.id = jud.rel_id_3
WHERE sub_1.member_group = $member_group
AND jud.pre = 1
GROUP BY jud.rel_id_1

但是,当我在页面中返回结果时,我得到一个只有一个条目 ID 的数组。

这是我用来生成结果的代码

$sql = "
    SELECT sub_1.entry_id, sub_2.entry_id, sub_3.entry_id
    FROM exp_judging_portfolios AS jud
    LEFT JOIN exp_submissions AS sub_1 ON sub_1.id = jud.rel_id_1
    LEFT JOIN exp_submissions AS sub_2 ON sub_2.id = jud.rel_id_2
    LEFT JOIN exp_submissions AS sub_3 ON sub_3.id = jud.rel_id_3
    WHERE sub_1.member_group = $member_group
    AND jud.pre = 1
    GROUP BY jud.rel_id_1
";
    $query = $this->EE->db->query($sql);
    $submissions_portfolio = $query->result_array();    

print_r($submissions_portfolio);   

这是返回的内容:

Array ( [0] => 354 ) 

有谁知道为什么?如果是这样,如何返回所有 3 个条目 ID?

4

1 回答 1

1

这次您只得到一个结果的原因是因为所有 3 个选定的 id 都具有相同的 alias entry_id。他们最终会互相覆盖。

您应该尝试以不同的方式命名它们:

SELECT sub_1.entry_id AS id_1, sub_2.entry_id AS id_2, sub_3.entry_id AS id_3

于 2013-10-03T12:00:13.497 回答