'PHP MySQL multiple table relationship not showing

I have 3 tables.

Table 1 is information about a user or customer. Table 2 is the schedule and activity set by the user or customer. Table 3 (Activity) is the activity table. Tickets will count how many have the same time and same activity from the database

Desired Output

+-------+------------+----------+
| time  |  act_name  | Tickets  |
+-------+------------+----------+
| 10:00 |  Jump      |     2    |
| 10:00 |  Run       |     1    |
| 11:00 |  Walk      |     1    |
| 12:00 |  Run       |     2    |
+-------+------------+----------+

Table 1

+------+------+
| id   | name |
+------+------+
|    1 | Joe  |
|    2 | Tony |
+------+------+

Table 2

+------+--------+------------+------------+--------+
| id   | act_id | tbl_id     |     date   |  time  |
+------+--------+------------+------------+--------+
|    1 |  1     |  1         | 03/03/2022 |  10:00 |
|    2 |  2     |  1         | 03/03/2022 |  10:00 |
|    3 |  3     |  1         | 03/03/2022 |  11:00 |
|    4 |  1     |  2         | 03/03/2022 |  11:00 |
|    5 |  2     |  2         | 03/03/2022 |  12:00 |
|    6 |  2     |  1         | 03/03/2022 |  12:00 |
|    7 |  1     |  2         | 03/03/2022 |  10:00 |
+------+--------+------------+------------+--------+

Activity

+------+----------+
| id   | act_name |
+------+----------+
|    1 | Jump     |
|    2 | Run      |
|    3 | Walk     |
+------+----------+

I wanted to display the information group by Activity name but if they have a different time set, they should be separated. This is what I did so far but it's not right since it's showing lots of activity names from the same time set but with different users.

Query:

SELECT 
    tbl1.*, 
    tbl2.*, 
    act.act_name 
FROM table1 as tbl1 
LEFT JOIN table2 as tbl2 ON tbl1 .id = tbl2.booking_id 
LEFT JOIN activity as act ON act.id = tbl2.activity_id 
WHERE 
    tbl2.date = '03/03/2022'
GROUP BY tbl2.time, tbl2.id
ORDER by tbl2.time ASC

Thank you in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source