复杂的 mysql 语句

Complicated mysql statement

您好,我需要显示客户订单的订单详细信息(orderid、customerid、itemdetails) 我有可用的 orderID 和 emali,电子邮件与我的 table 中的客户 ID 对应,当我尝试以下语句时

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

它工作正常但是我需要使用客户电子邮件而不是 customerID 但 customerID 是我在 table 之间的 link 所以我需要在声明中包含它。我如何使用 union 或如何 link 将 table 客户 ID 和电子邮件中的相应字段组合在一起。

我的客户 table 有 customerID、customerName、customerSurname、电子邮件

订单table有orderID、customerID

和 orderItem table 有 orderID 和所有项目的详细信息

有什么想法请分享

您可以像这样将表格连接在一起:

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 ]