处理sql 自连接 的问题 distinct 'null'

1.先看一下这段代码:
select car.vin from car_info_temp car join (
select brand from car_info_temp car where car.dealer_code=#{code} group by brand
) car1 on car.brand=car1.brand

我的疑问是 vin brand 是来自一个表 为什么不一次查?
select Distinct brand,vin from car_info_temp car where car.dealer_code=#{code}

这样一次查,查询是不一样的
上面自连接 通过dealer_code查到品牌brand 再查到brand下面所有的vin
一次查 通过dealer_code查到品牌brand 再查到brand下面dealer_code为给定code的vin

2.
select distinct 'null' as level ,series as series from car_info_temp car join (
select brand from car_info_temp car where car.dealer_code=#{code} group by brand
) car1 on car.brand=car1.brand

distinct 'null'这里是把返回的多列的null值处理成一条
原文地址:https://www.cnblogs.com/yxj808/p/13043292.html