作业帮 > 综合 > 作业

数据库表关联的问题select xxxfrom a表 aleft join d表 d on a.product_inst

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/10/04 19:22:18
数据库表关联的问题
select xxx
from a表 a
left join d表 d
on a.product_instance_id = d.product_instance_id
and d.attr_id in ('500010001293','500010002690','200000001908')

select xxx
from a表 a
left join d表 d
on a.product_instance_id = d.product_instance_id
where d.attr_id in ('500010001293','500010002690','200000001908')
这两段SQL的结果一样吗?数据库达牛帮忙看看,
不一样的,左连接方式.
第一个用and不用where的方法,不太起作用,有明会有多余的数据,包括部分字段会显示null.
第二个采用where条件,则严格按一对一处理,关联不上的数据不显示.
建议采用where方法编程,代码易读,且不会出现其它数据问题.