I have three tables- sales, sales_details, medicine. From sales table, I'll collect the sale_id and with that I'll get details of a particular sale from sales_details. Along with that, in the sales_details, there is one cell for medicine id (mid). Using that mid, I would also like to get the medicine name and return all of the data in one query.
Here is what I have so far-
SELECT `mid`, `qty`, `rate`, `total_price`, `discount`, `total_discount`, (SELECT `medicine`.`product_name` FROM `medicine` WHERE `sales_details`.`mid` = `medicine`.`product_id`) AS 'medicine_name'
FROM `sales_details`
WHERE `sale_id` IN (SELECT `sale_id` FROM `sales` WHERE `invoice_no` = '$invoiceID;
I get all the data including mid but medicine_name is null in each row. What is wrong in the query plz?