Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
内部连接mysql连接3个表_Mysql_Sql_Inner Join - Fatal编程技术网

内部连接mysql连接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

我在使用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 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;