oracle left join 无法查出左表的全部数据,很疑惑
有如下sql语句
select st.name,count(si.id) from t_school_type st left join t_school_info si on st.id = si.t_s_id where si.record_status = 1 group by st.name;
select st.name,count(si.id)from t_school_type st left join (select * from t_school_info where record_status = 1)si on st.id = si.t_s_idgroup by st.name;
[解决办法]
select st.name,count(si.id)
from t_school_type st
left join t_school_info si on st.id = si.t_s_id
where si.record_status = 1
group by st.name;
------------------------------
the result will be
STEP 1:
select * from t_school_type st left join t_school_info si on st.id = si.t_s_id;
this sql will find out every entry in table t_school_type;
we can name the result as "resulttable"
but after you add where condition
STEP 2:
select name,count(id) from resulttable where record_status=1 group by name;
the result will be filted.
So that's why you got the result like that, it's true.