I have two tables:
我有两张桌子:
toys
item_id int(4) unsigned
item_id int(4)unsigned
item_desc varchar(100)
initial_quantity int(4) unsigned
initial_quantity int(4)unsigned
price decimal(5,2)
and
toy_purchases
item_id int(4) unsigned
item_id int(4)unsigned
customer_name varchar(100)
quantity int(4) unsigned
quantity int(4)unsigned
purchase_date date
Only using aliases, how would I list out only the item description from the toys table, along with only the customer_name and purchase_date (whether or not they exist) from toy_purchases.
仅使用别名,我将如何仅从toy_purchases中列出玩具表中的项目描述以及customer_name和purchase_date(无论它们是否存在)。
I have tried the following:
我尝试过以下方法:
select b.book_name
from books as b
left outer join bc.customer_name, bc.purchase_date
from book_customers as bc on b.bookid=bc.itemid;
1 个解决方案
#1
1
That is not the proper syntax for a query. I think you are actually after:
这不是查询的正确语法。我想你实际上是在追求:
SELECT t.item_desc AS Description,
tp.customer_name AS Customer,
tp.purchase_date AS DatePurchased
FROM toys t
LEFT JOIN toy_purchases tp ON t.item_id = tp.item_id
#1
1
That is not the proper syntax for a query. I think you are actually after:
这不是查询的正确语法。我想你实际上是在追求:
SELECT t.item_desc AS Description,
tp.customer_name AS Customer,
tp.purchase_date AS DatePurchased
FROM toys t
LEFT JOIN toy_purchases tp ON t.item_id = tp.item_id