mysql链接4个表和一些条件

时间:2015-04-14 21:50:29

标签: mysql

我试图将这4张表联系起来,但我一直遇到问题。有没有人知道为什么?

Part (
  part_num,
  description,
  on_hand
)

Order (
  order_num,
  date,
  customer_id
)

Order_line (
  part_num,
  order_num,
  price
)

Customer (
  customer_ID,
  customer_name
)

我正在尝试为名称为order_num和说明date的{​​{1}}提取customer"raymond"

"stove"

我点击了输入,显示为:SELECT order.order_num, date FROM order, part, order_line, customer WHERE order.order_num = order_line.order_num AND part.part_num = order_line.part_num AND order.customer_id = customer.customer_id AND customer_name = 'raymond' AND description = 'stove' ; 而不是,>

1 个答案:

答案 0 :(得分:0)

您需要选择part.part_num,如下所示,同时转发order它是一个关键字:

Select part.part_num,date
from `order`, part, order_line, customer
where `order`.order_num = order_line.order_num
and part.part_num = order_line.part_num
and `order`.customer_id = customer.customer_id
and customer_name = 'raymond' 
and description = 'stove' ;