【问题标题】:SQL Command not properly ended trying to join 3 tables using querySQL 命令未正确结束尝试使用查询连接 3 个表
【发布时间】:2020-05-10 20:22:37
【问题描述】:

您好,我正在尝试将 Product_descriptions 表中的 Translated_Name 列添加到已连接两个表的当前查询中,但 translate_name 列是 NVARCHAR2 类型。我应该使用 Inner Join 还是我完全错了?

select order_mode,customer_id,product_id from ORDERS
       inner join ORDER_items on order_items.ORDER_ID=Orders.ORDER_ID
where exists(select customer_id from customers where orders.customer_id=customers.customer_id)
       inner join product_descriptions on product_descriptions.translated_name = Orders.Customer_id

【问题讨论】:

    标签: sql oracle join oracle-apex


    【解决方案1】:

    where 子句在joins 之后:

    select  
        order_mode,
        customer_id,
        product_id 
    from orders o
    inner join order_items oi 
        on oi.order_id = o.order_id
    inner join product_descriptions pd 
        on pd.translated_name = o.customer_id
    where exists(
        select 1
        from customers c 
        where o.customer_id = c.customer_id
    )
    

    注意事项:

    • 表别名使查询更易于读写

    • 您应该使用它们所属的表的别名来限定 from 子句中的列

    • 我很怀疑product_descriptions上的join条件,涉及到customer_id;您可能需要检查一下(在不了解您的表结构的情况下,无法判断正确的条件是什么)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-27
      • 1970-01-01
      • 2011-09-15
      • 1970-01-01
      相关资源
      最近更新 更多