php - SQL to select common as well as remaining data using JOIN in MySQL -



php - SQL to select common as well as remaining data using JOIN in MySQL -

i have 3 tables: wi_district, wi_group, , wi_training. need count groups , trainings based on districts. purpose have used next sql;

sql1 select wi_district.dst_name, count(grp_id) group_count, max(grp_created_date) grp_created_date wi_group inner bring together wi_district on wi_district.dst_id=wi_group.grp_dst_id , wi_group.grp_deleted=0 , wi_group.grp_type in (3) grouping wi_district.dst_name

the query counts grouping each district. likewise,

sql2 select wi_district.dst_name, count(trn_id) training_count, max(trn_created_date) trn_created_date wi_training inner bring together wi_district on wi_district.dst_id=wi_training.dst_id , wi_training.trn_deleted=0 , wi_training.trn_beneficiary_type in (-1,2,8,9,10) grouping wi_district.dst_name

the query counts training each district. need combine results obtained sql1 , sql2 , result in form of

dst_name || group_count || grp_created_date || training_count || trn_created_date

the problem whenever used sql1 left bring together sql2 displayed result respective sql1 result of sql2 can't obtained , vice-versa. please help me sort out problem in mysql

i think can bring together filtered tables , grouping district name. so:

select dist.dst_name dst_name, count(grp.grp_id) group_count, max(grp.grp_created_date) grp_created_date, count(trn.trn_id) training_count, max(trn.trn_created_date) trn_created_date wi_district dist left bring together ( select dst_id, trn_id, trn_created_date wi_training trn_deleted=0 , trn_beneficiary_type in (-1,2,8,9,10) ) trn on trn.dst_id=dist.dst_id left bring together ( select grp_dst_id, grp_id, grp_created_date wi_group grp_deleted=0 , grp_type in (3) ) grp on grp.grp_dst_id = dist.dst_id grouping dist.dst_name

php mysql sql join

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -