内连接mysql x3

时间:2014-10-17 15:09:37

标签: mysql sql inner-join

我需要显示cust_id,客户的姓名和姓氏,产品名称&lt ;-(来自产品表)和销售日期< - (来自销售表),我还需要按最近的日期顺序显示第一

这是我到目前为止所得到的:

SELECT   
   customer.cust_id, 
   customer.forename, 
   customer.surname, 
   products.prod_name, 
   sales.Date_of_sale
FROM customers c
    INNER JOIN sales s ON c.cust_id = s.cust_id
    INNER JOIN products p ON s.product_id = p.product_id
ORDER BY s.Date_of_sale DESC

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

SELECT   
   c.cust_id, 
   c.forename, 
   c.surname, 
   p.prod_name, 
   s.Date_of_sale
FROM customers c
    INNER JOIN sales s ON c.cust_id = s.cust_id
    INNER JOIN products p ON s.product_id = p.product_id
ORDER BY s.Date_of_sale DESC

将起作用