I have 3 tables: 2 tables and 1 SQL view. I am not getting right results.
1 table
CREATE TABLE `salary_earning` (
  `id` int NOT NULL AUTO_INCREMENT,
  `basic_salary` int NOT NULL,
  `health_allowance` int NOT NULL,
  `transport_allowance` int NOT NULL,
  `overtime_allowance` int NOT NULL,
  `leave_encashment` int NOT NULL,
  `accomodation_allowance` int NOT NULL,
  `bonus_allowance` int NOT NULL,
  `emp_id` varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  `date` date NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; 
INSERT INTO `salary_earning` VALUES
(1, 100, 20, 15, 10, 5, 30, 5, 101, '2020-10-10');
INSERT INTO `salary_earning` VALUES
(2, 0, 0, 0, 0, 0, 0, 30, 101, '2020-10-11');
INSERT INTO `salary_earning` VALUES
(3, 100, 20, 15, 10, 5, 30, 5, 102, '2020-11-10');
2 table
CREATE TABLE `salary_deduction` (
 `id` int NOT NULL AUTO_INCREMENT,
 `income_tax` int NOT NULL,
 `advance_money` int NOT NULL,
 `emp_id` varchar(60) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
 `date` date NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `salary_deduction` VALUES
(1, 12, 30, '101', '2020-10-10');
3 view
SELECT 
    slr.*,
    `total_earning` - `total_deduction` AS `final_salary`
FROM (
  SELECT 
    `se`.`emp_id`,
    `se`.`date`,
    (
        `basic_salary`+
        `health_allowance`+
        `transport_allowance`+
        `overtime_allowance`+
        `leave_encashment`+
        `accomodation_allowance`+
        `bonus_allowance`
    ) AS `total_earning`,
    IFNULL(`income_tax` + `advance_money`, 0) AS `total_deduction`
  FROM `salary_earning` `se`
  LEFT JOIN `salary_deduction` `sd` ON 
    `se`.`emp_id` = `sd`.`emp_id` AND `se`.`date` = `sd`.`date`
) slr;
CURRENT OUTPUT
+--------+------------+---------------+-----------------+--------------+
| emp_id |       date | total_earning | total_deduction | final_salary |
+--------+------------+---------------+-----------------+--------------+
|    101 | 2020-10-10 |           185 |              42 |          143 |
|    101 | 2020-10-11 |            30 |               0 |           30 |
|    102 | 2020-11-10 |           185 |               0 |          185 |
+--------+------------+---------------+-----------------+--------------+
DESIRED OUTPUT/WHAT IAM LOOKING FOR
+--------+------------+---------------+-----------------+--------------+
| emp_id |       date | total_earning | total_deduction | final_salary |
+--------+------------+---------------+-----------------+--------------+
|    101 | Oct 20     |           215 |              42 |          173 |
|    102 | Nov 20     |           185 |               0 |          185 |
+--------+------------+---------------+-----------------+--------------+
So, i want an aggregate for a full month if a new value(either under earning or deduction) is added with same emp_id. Can you help me what I am doing wrong.
 
     
    
