我有下面的查询工作正常,但我想通过添加另一个条件来修改它,但我不知道如何去做。我要添加的内容显示在第二个查询中,但它不起作用。
$results_pref_school1 = $db->query('SELECT mps.mps_client_ec_no,mcs.mcs_client_ec_no
FROM match_pref_schools AS mps
INNER JOIN match_current_schools AS mcs
ON mps.mps_school_id = mcs.mcs_school_id
WHERE mcs.mcs_id IN (SELECT MIN(mcs.mcs_id)
FROM match_current_schools AS mcs
GROUP BY mcs.mcs_school_id)
ORDER BY mcs.mcs_id');
我只需要具有'A'状态的结果
$results_pref_school1 = $db->query('SELECT mps.mps_client_ec_no,mcs.mcs_client_ec_no
FROM match_pref_schools AS mps
INNER JOIN match_current_schools AS mcs
ON mps.mps_school_id = mcs.mcs_school_id
WHERE mcs.mcs_id IN (SELECT MIN(mcs.mcs_id)
FROM match_current_schools AS mcs
GROUP BY mcs.mcs_school_id)
AND mps.mps_status = "A"
AND mcs.mcs_status = "A"
ORDER BY mcs.mcs_id');
答案 0 :(得分:0)
我不是100%肯定我正在回答你想要问的问题,但你可以通过使用括号在on
条款中有多个条件
select
*
from
table_1
inner join table_2 on(
table_2.column_1 = table_1.column
and (
table_2.other_column = 'value'
or table_2.other_column = 'other value'
)
)
答案 1 :(得分:0)
您可以尝试:
SELECT mps.mps_client_ec_no,mcs.mcs_client_ec_no
FROM match_pref_schools AS mps
INNER JOIN match_current_schools AS mcs
ON mps.mps_school_id = mcs.mcs_school_id
AND mps.mps_status = "A"
AND mcs.mcs_status = "A"
WHERE mcs.mcs_id IN (
SELECT MIN(mcs.mcs_id)
FROM match_current_schools AS mcs
GROUP BY mcs.mcs_school_id)
ORDER BY mcs.mcs_id
)