user3396201
user3396201

Reputation:

Complicated mysql statement

hi i need to display order details for customer order (orderid, customerid, itemdetails ) i have avalible orderID and emali, email is coresponding to customer id in my table and when i try following statement

select a.*, b.* from customer_order a, order_item b where a.orderID = b.orderID and customerID = 30;

it works fine however i need to use customer email instead of customerID but customerID is my link between tables so i need to have it in statement. how can i use union or how i can link together corresponding fields in table customerID and email.

my customer table have customerID, customerName, customerSurname,email

order table have orderID, customerID

and orderItem table have orderID and all items details

please share if you have any ideas

Upvotes: 0

Views: 36

Answers (1)

Mark Madej
Mark Madej

Reputation: 1922

You can probably just join the tables together like this:

SELECT
    co.*, oi.*
FROM
customer c
JOIN customer_order co ON c.customerID = co.customerID
JOIN order_item oi ON co.orderID = oi.orderID
WHERE
c.email = [ the email you want ]

Upvotes: 2

Related Questions