exists和no exists
http://hi.baidu.com/yds_amber/blog/item/0f64cfcf2c91b13bf8dc61d2.html
SELECT *
FROM a left join b on a.id=b.id2
where not exists (select 1 from b b1 where b.id2 = b1.id2 and b.xh > b1.xh)
就是不在这个范围的意思
select id
from table
where name not exists(select 1
from table
where name = 'aaa')
也许你看不懂这个1的意思,不过在使用EXISTS的时候,通常都会使用1,它代表所查询出来的集合,等同
于select name。
整个例子的意思是:查询name不等于aaa的所有ID。
b.xh > b1.xh
这里是同一个表中字段相比较。是找出最小型了,可是怎么确定是那一产品的最小型号?
是不是外层的语句已经把范围定在某一产品了?
http://topic.csdn.net/u/20081107/15/307c24ec-062c-4daf-81ed-8df77ce97d7d.html?
seed=1355347129