2016-08-01 57 views
2

我一直在研究MySQL,通过一本名为'PHP和MySQL Web Development'的书,我正在讲授如何从多个表中查询数据的一章,我试图在我自己并想出了下面的命令查询MySQL上的多个表

mysql> select customers.name from books, customers, orders, orders_items 
    -> where books.title = 'Java 2' 
    -> and books.isbn = orders_items.isbn 
    -> and orders_items.orderid = orders.orderid 
    -> and orders.customersid = customers.customerid; 

,并返回我下面的错误

ERROR 1146 (42S02): Table 'books.orders_items' doesn't exist 

但是当我尝试使用完全相同的命令,因为它是在它工作得很好,这本书

mysql>select customers.name from customers, orders, order_items, books 
    ->where customers.customerid = orders.customerid 
    ->and orders.orderid = order_items.orderid 
    ->and order_items.isbn = books.isbn 
    ->and books.title = 'Java 2'; 

+-------------+ 
| name  | 
+-------------+ 
| Julie Smith | 
+-------------+ 

除了标准的顺序,我在这里还缺少什么? 我还没有在任何地方输入books.orders_items

+0

你能描述/显示涉及的表架构? – RamRaider

回答

2

您使用的是复数orders_items不是单一从书order_items

都在这里

从书本,客户,订单选择customers.name,orders_items

并在线

和books.isbn = orders_items .isbn

+0

男孩我现在觉得很笨?大声笑我想这个错误是一个表内的列,但它是一个数据库内的表 –