Emolk Emolk - 4 months ago 5x
SQL Question

MQL, PHP select all from two tables?

So i have two tables:


| ProductID | Quantity


| ProductID | productname | Desc | Price | Stock | Image

and i need to get all of the same product ID, show their quantity then times that by their price and show the grand total of all.

My problem is i'm trying to show a checkout page which shows everything in a list, but how do i combine the two tables? Also, there are no foreign keys for the first table.

I need this in an sql statement as well preferably, like:

$sql = 'SELECT...'

Would this work?

$sql = "SELECT * FROM order_products
SELECT * FROM products"

If so, how do i know which row is which?

My desired output is all entries, now looking like this:

ProductID | Quantity | Productname | Desc | Price | Stock | Image


You need a classical JOIN clause:

   SELECT * 
     FROM products
LEFT JOIN order_products on products.ProductId = order_products.ProductId