I'm trying to join a few tables as I'll need values that are within all of them.
I've tried two ways so far:
First way:
SELECT o.`order_id` as `Order ID`, o.`STATUS` as `Order Status`, o.`date_created` as `Date Created`, op.`SKU`, op.`NAME`, o.`STATE`, op.`QUANTITY`, c.`customer_id` FROM `orderProducts` op INNER JOIN orders o on op.order_id = o.order_id INNER JOIN customers c on c.customer_id = o.customer_id WHERE o.order_id IN (616898, 616901) Second way:
SELECT o.`order_id` as `Order ID`, o.`STATUS` as `Order Status`, o.`date_created` as `Date Created`, op.`SKU`, op.`NAME`, o.`STATE`, op.`QUANTITY`, c.`customer_id` FROM `orders` o, `orderproducts` op, `customers` c WHERE o.order_id IN (616898, 616901) AND c.customer_id= o.customer_id AND o.order_id = op.order_id Tables data:
orders
+----------------------------+------------+------+-----+ | Field | Type | Null | Key | +----------------------------+------------+------+-----+ | order_id | int(11) | NO | PRI | | customer_id | int(11) | YES | | orderproducts
+----------------------------+------------+------+-----+ | Field | Type | Null | Key | +----------------------------+------------+------+-----+ | order_id | int(11) | NO | | customers
+----------------------------+------------+------+-----+ | Field | Type | Null | Key | +----------------------------+------------+------+-----+ | customer_id | int(11) | NO | PRI | Sorry, but I don't really know how to represent the data I want out, I'll try my best to explain it.
I want the columns in my select statement, from the orders 616898 and 616901. The order_id field is the same in both the order and orderproducts tables. The customer_id field is the same in both the order and customers tables. It's like I'm adding extra columns SKU, NAME, QUANTITY from orderproducts table using the order_id to extract the correct ones and the column email, using the customer_id from the orders and the customers table.