I have 3 tables where I am trying to put a join query like below.
The below is the Section table containing 3 sections.
Section
*****************************
* section_id * section_name *
*****************************
* 1 * A *
* 2 * B *
* 3 * C *
*****************************
The below is the section_subject table. 1st section contains 2 subjects, 2nd section contains 2 subjects and 3rd section contains 3 subjects.
Section_Subject
***********************************
* ss_id * section_id * subject_id *
***********************************
* 1 * 1 * 8 *
* 2 * 1 * 9 *
* 3 * 2 * 6 *
* 4 * 2 * 5 *
* 5 * 3 * 2 *
* 6 * 3 * 3 *
* 7 * 3 * 4 *
***********************************
The below is the section_batch table. 3rd section alone contains 2 batches
Section_Batch
*********************************
* sb_id * section_id * batch_id *
*********************************
* 1 * 3 * 6 *
* 2 * 3 * 7 *
*********************************
I want a query to yield the below result
**************************************************************
* section_id * section_name * count_subjects * count_batches *
**************************************************************
* 1 * A * 2 * 0 *
* 2 * B * 2 * 0 *
* 3 * C * 3 * 2 *
**************************************************************
I know that we can do some kind of sub query and achieve the above result. But how to get the result using left join and group query?