我在使用 3 个表的内部联接时遇到问题..
我需要显示 cust_id、客户姓名、产品名称<-(来自产品表)和销售日期<--(来自销售表),我还需要按最近日期的顺序显示首先。
这就是我到目前为止所得到的
enter SELECT
customers.cust_id,
customers.forename,
customers.surname,
products.prod_name,
sales.Date_of_sale
FROM
customers
INNER JOIN
sales
ON
customers.cust_id = sales.cust_id; here
如果您能在这里帮助我,我真的很感激,谢谢..
最佳答案
只需向 products
表再添加一个 JOIN
并包含 ORDER BY
子句即可:
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
关于mysql - 内连接mysql连接3个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26414517/