I have two tables vendor
and medicines
on mysql database now i need to count total medicines transacted based on vendor ID with a condition status is equal to paid, in a single query and show it to my users
My vendor table looks like this
| ID | vendor_name |
+----+------------------+
| 1 | Marakel Medicine |
| 2 | Ignacio Pharmacy |
| 3 | Rico Medicines |
| 4 | Marco Pharmacy |
+----+------------------+
My Medicines table looks like this.
| ID | vendor_id | medicine_name | Status |
+----+-----------+----------------+---------+
| 1 | 1 | paracetamol #1 | paid |
| 2 | 1 | paracetamol #1 | paid |
| 3 | 2 | paracetamol #1 | pending |
| 4 | 2 | paracetamol #1 | paid |
| 5 | 4 | paracetamol #1 | paid |
+----+-----------+----------------+---------+
My desire output would be like this
+----+------------------+-----------+
| ID | vendor_name | Total Med |
+----+------------------+-----------+
| 1 | Marakel Medicine | 2 |
| 2 | Ignacio Pharmacy | 1 |
| 3 | Rico Medicines | 0 |
| 4 | Marco Pharmacy | 1 |
+----+------------------+-----------+
So far my code is below i was able to output per vendor i just don't have an idea how to count them based on there status, any suggestion would be great!
SELECT * FROM vendors LEFT JOIN medicine ON vendor.ID = medicines.vendor_id