Doubts about subqueries and table join queries

doubts about subqueries and table join queries

there are two tables, user (user) and user_dictionary (user Dictionary), and then my colleague struggles with me with a problem. Forgive me for this scum who doesn"t know

.

related codes

user: industry, occupation, grade, etc. Multiple selective attributes
user_dictionary: type, value, value name

now there are two sql, which is more efficient

1:
select u.farmer,
(select ud. Value name from user_dictionary ud where ud. Type = "Industry" and ud. Value = u. Industry) as" Industry name",
(select ud. Value name from user_dictionary ud where ud. Type = "occupation" and ud. Value = u. Occupation) as" occupation name",
(select ud. Value name from user_dictionary ud where ud. Type = "level" and ud. Value = u. As" level name",
from user u

2:
select u.handwriting ud1. Value name, ud2. Value name, ud3. Value name
from user u
left join user_dictionary ud1 on u. Industry = "set industry number" and ud1. Value = u. Industry
left join user_dictionary ud2 on u. Occupation = "set occupation number" and ud1. Value = u. Occupation
left join user_dictionary ud3 on u. Level = "set level number" and ud1. Value = u. Grade

I want to know which method is recommended (method 1 I use, colleagues are those who are stubborn and totally stick to their own ideas)

Apr.01,2021

which one is more efficient? just take a look at the execution time, and then explain it.
say something beside the point: when you think your colleague is the kind of person who is stubborn and completely insists on his own ideas, maybe he thinks the same about you, why do you have to let others write code the way you want? Unless you encounter a serious efficiency problem


there is no doubt: 2, you can explain the results yourself

Menu