账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    关于子查询和表连接查询的疑惑
    28
    0

    关于子查询和表连接查询的疑惑

    存在2张表user(用户) 和 user_dictionary(用户字典) 2张表,然后同事与我纠结一个问题,原谅我这渣渣不知道

    相关代码

    user:行业,职业,等级 等等多选择性属性
    user_dictionary:类型,值,值名称

    现在有2个sql,哪一个效率跟高

    1:
    select u.*,
    (select ud.值名字 from user_dictionary ud where ud.类型='行业' and ud.值=u.行业) as '行业名称',
    (select ud.值名字 from user_dictionary ud where ud.类型='职业' and ud.值=u.职业) as '职业名称',
    (select ud.值名字 from user_dictionary ud where ud.类型='等级' and ud.值=u.等级) as '等级名称',
    from user u

    2:
    select u.*,ud1.值名称,ud2.值名称,ud3.值名称
    from user u
    left join user_dictionary ud1 on u.行业='设置的行业编号' and ud1.值=u.行业
    left join user_dictionary ud2 on u.职业='设置的职业编号' and ud1.值=u.职业
    left join user_dictionary ud3 on u.等级='设置的等级编号' and ud1.值=u.等级

    我想知道推荐使用哪一种方式(我使用的方式1,同事属于那种死脑筋,完全坚持自己想法的人)

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 寡ジ交◣ 普通会员 1楼
      502 Bad Gateway

      502 Bad Gateway


      nginx
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部