I have a MySQL query where i'm trying to lookup a products name in one table from another table based on it's ID as follows:
mysqli_query("SELECT product, expirydate, SUM(quantity), status FROM stockmovement a LEFT JOIN (SELECT productid, product AS productname FROM products) b ON a.product = b.productid WHERE a.status = '0' GROUP BY a.product, a.expirydate HAVING SUM(a.quantity) > 0 ORDER BY a.product, a.expirydate ASC"); Everything works apart from the left join which returns blank when i try to output 'productname'. Can anybody see where the query is going wrong?
Thanks in advance and Merry Christmas :)
a.producttob.productid... is that correct? Without knowing the data, it looks like you'd wantb.productinstead.