wind-flyer 2021-12-21 11:06 采纳率: 100%
浏览 54
已结题

使用left ioin on ,sql报错:an on clause has an invalid table reference

问题遇到的现象和发生背景

sql提数时a,b,c表数据是完整的,但是d 表数据不完整只有一部分,
正常的如果使用唯一字段a.id = d.id直接去关联的话,查出来的数据也是不完整的,只有d表所有的数据。

希望的结果是能提出a表中完整的数据,如果数据在d表不存在,则显示为null

例如以下语句提出来的是只有d表有的数据,譬如d表是100条,但是a表数据有200条,提出来只有100条,希望是能提出200条。

select a.id,a.name,b.age,c.class,d.score
from table1 a,table2 b,table3 c,table4 d
where a.id = b.id
and a.id = c.id
and a.id = d.id
and b.score > '60'

使用left join,报错提示:an on clause has an invalid table reference,不知道哪里存在问题,烦请帮忙看下,谢谢

select a.id,a.name,b.age,c.class,d.score
from table1 a,table2 b,table3 c
left  join table4 d

on a.id = d.id
where a.id = b.id
and a.id = c.id
and b.score > '60'
  • 写回答

2条回答 默认 最新

  • DarkAthena ORACLE应用及数据库设计方案咨询师 2021-12-21 14:23
    关注
    select a.id,a.name,b.age,c.class,d.score
    from table1 a,table2 b,table3 c
    left  join table4 d
     
    on c.id = d.id
    where a.id = b.id
    and a.id = c.id
    and b.score > '60'
    

    由于你left join 前后是C表和D表,所以on的字段只能在C和D里面选,你要么改成on c.id = d.id ,要么把表的排列顺序换下,把a表放到left join前面去

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 12月29日
  • 已采纳回答 12月21日
  • 创建了问题 12月21日

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序