从具有相同where子句的多个表中进行选择

时间:2017-07-01 15:14:32

标签: mysql sql select

我收到错误:

  

专栏'赛季' in where子句不明确

并且无法弄清楚如何修复它。

$fg_leader_id_query = mysql_query("SELECT * FROM stats_pd, stats_int, stats_ha, stats_ke, stats_ka, stats_kn, stats_lv, stats_sv, stats_snv WHERE `season`='".$season."' ORDER BY fgm/fga DESC LIMIT 1") or die(mysql_error());

我需要从列表季节等于$season的每个表中获取行。

1 个答案:

答案 0 :(得分:0)

尝试:

$fg_leader_id_query = mysql_query("
SELECT * 
FROM stats_pd, stats_int, stats_ha, stats_ke, stats_ka, stats_kn, stats_lv, stats_sv, stats_snv  
WHERE 
        `stats_pd.season`='".$season." OR
        `stats_int.season`='".$season." OR
        `stats_ha.season`='".$season." OR
        `stats_ke.season`='".$season." OR
        `stats_ka.season`='".$season." OR
        `stats_kn.season`='".$season." OR
        `stats_lv.season`='".$season." OR
        `stats_sv.season`='".$season." OR
        `stats_snv.season`='".$season."' 
ORDER BY fgm/fga DESC LIMIT 1
") or die(mysql_error());