内部连接mysql连接3个表
我在使用3个表的内部联接时遇到问题内部连接mysql连接3个表,mysql,sql,inner-join,Mysql,Sql,Inner Join,我在使用3个表的内部联接时遇到问题 我需要显示客户id、客户姓名和姓氏、产品名称只需在产品表中再添加一个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 produ
我需要显示客户id、客户姓名和姓氏、产品名称只需在
产品表中再添加一个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
我认为问题出在FROM参数中。
您只指定了客户
SELECT customers.cust_id, customers.forename, customers.surname, products.prod_name, sales.Date_of_sale
FROM
customers , products , sales
INNER JOIN
sales
ON
customers.cust_id = sales.cust_id;
我收到错误#1066-非唯一表/别名:“sales”请帮助此操作无效我收到错误-->#1054-on子句中的未知列“s.product_id”
SELECT customers.cust_id, customers.forename, customers.surname, products.prod_name, sales.Date_of_sale
FROM
customers , products , sales
INNER JOIN
sales
ON
customers.cust_id = sales.cust_id;