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'
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前面去
你要用笛卡尔积就都用笛卡尔积,要用left join就都用left join,不要混着用
你的第二种写法其实是c和d做left join,再与a和b一起做笛卡尔积,所以既然是c,d做left join,当然找不到a是个什么了