SQL主表、从表

1.关于主表和从表怎么选择的问题

select * from table,  from后边的是主表,join 后边的是从表

常见的是取的字段多的表是主表,但不是常见的不一定每次都是对的。

还要看后边where 是用那张表的字段去做过滤,

select
a.id as menuId,
a.name,
a.icon_url,
a.type,
a.h5_url,
a.android_url,
a.ios_url,
a.pc_url,
a.desc,
a.h5_url_type
from  b left join  a on a.id = b.menu_id
where b.type = #{type} and b.is_del = 0

就像这个sql字段都是a的,但是where删选是在b表里,这时就选b表作为主表。这样是先做删选,再去join,效率高

下班记得打卡
原文地址:https://www.cnblogs.com/onlyzhangmeng/p/13930695.html