mysql - What's wrong with given query regarding displaying ad counters for categories? -
i have asp.net website users can put ads. in there want display ad counters each category. using mysql db.
to using query
select type.`type_id_pk`, type.`name`, count(head.`header_id_pk`) `count` `testdb`.`type` `type` left join `header` head on head.`type_id_fk` = type.`type_id_pk` group type.`type_id_pk` order `name` asc ; above query works fine. in site separate ads in countries. want display ad counters country. modified above query this
select type.`type_id_pk`, type.`name`, count(head.`header_id_pk`) `count` `testdb`.`type` `type` left join `header` head on head.`type_id_fk` = type.`type_id_pk` head.`country_id_fk` = _country_id group type.`type_id_pk` order `name` asc ; _country_id place insert specific country id. above query returns rows have ads. if there no ad category not displaying. so want display categories along counters specific country.( including 0 ad categories) .so whats wrong above query? ( please consider query efficiency. )
essentially code seems enforce inner join, null results excluded. might try left outer join include null results, , lighten restriction in where clause weeds out null results.
left outer join `header` head on head.`type_id_fk` = type.`type_id_pk` head.`country_id_fk` = _country_id or head.`country_id_fk` null
Comments
Post a Comment