比较懒,来几张图片
SQL查询1:SQL查询2:
SQL查询3:
SQL查询4:
对比以上的数据,可以确定是inner join数据后排序的问题,但是为什么是在top 2 和top 3之间?
不知道理解是否正确,使用inner join 如果未指定排序, 数据库会自动选择最优的排序来排,比如上面的结果,
当top 1 top 2的时候,数据量小,所以直接返回的是根据id排序的结果,
当top 3的时候数据库认为先根据brandid来排序,再根据产品id更优,所以排序就变了
当使用top N, N数字比brandid=1的数量大时候,top N 的排序又变成了根据id排序.
当给查询语句加上where条件时候,排序又变了,所以对inner join是如何排序的很费解?这总该有个规律吧? 谁知道麻烦告知下