常见数据库SQL查询优化----应付面试

一. 单表查询

order by

order by 字段建立索引的前提是where后的字段也建立了索引

group by

group by 可以建立索引,并不需要where后的字段建立索引

where a = 3 and b > 4 and c = 5

使用到ab c不能用在范围之后,b断了

where a = 3 and b like 'k%kk%' and c = 4

Y,使用到a,b,c

二.多表

inner join

选择表列数比较大的表,进行创建索引(表大的)

left join

只能是左表进行全表扫描

使用left join .. where ...  is null  代替 not in (子查询)

 

猜你喜欢

转载自blog.csdn.net/qq_43193797/article/details/85259672
今日推荐