Home > database >  Which is more efficient SQL?
Which is more efficient SQL?

Time:09-20

Writing a (left) :

The select t.w onum, t.d escription, t.s tatus, t.l ocation, a. d. escription, t.j pnum, b.d escription,
Tc hangeby, c.d isplayname, t.p mnum, d.d escription, t.o wnergroup, e.d escription,
T.p ersongroup, f.d escription, t.l ead, g.d isplayname
The from workorder t
Left the join locations on a. a. ocation=t.l ocation
Left the join jobplan b on b.j pnum=t.j pnum and b.s tatus='activities'
Left the join person c on c.p ersonid=tc hangeby
Left the join PM d on d.p mnum=t.p mnum
Left the join persongroup e on e.p ersongroup=t.o wnergroup
Left the join persongroup f on f.p ersongroup=t.p ersongroup
Left the join person g on g.p ersonid=t.l ead
Where t.w oclass='work order;

Write 2 (the subquery) :

The select t.w onum, t.d escription, t.s tatus,
T.l ocation, (select a. d. escription the from locations where a a. ocation=t.l ocation),
T.j pnum, (select b.d escription the from jobplan b where b.j pnum=t.j pnum and b.s tatus='activities'),
Tc hangeby, (select c.d isplayname from person c where c.p ersonid=tc hangeby),
T.p mnum, (select d.d escription the from PM d where d.p mnum=t.p mnum),
T.o wnergroup, (select e.d escription the from persongroup e where e.p ersongroup=t.o wnergroup),
T.p ersongroup, (select f.d escription the From persongroup f the where f.p ersongroup=t.p ersongroup),
T.l ead, (select g.d isplayname from person g where g.p ersonid=t.l ead)
The from workorder t
Where t.w oclass='work order;

CodePudding user response:

People tend to be what kind of writing?

CodePudding user response:

If you can connect to realize you are about to use connect the subquery efficiency is lower than it

CodePudding user response:

This depends on data volume, the amount of data in the subquery is large, suggest the subquery,

Specific how to do, but also see the execution plan, this is the most accurate,

CodePudding user response:

The subquery is clear

CodePudding user response:

Reading is the first to see clear

CodePudding user response:

Is usually left connection, certain of time, with the subquery, to see whether the data structure and implementation plan,

CodePudding user response:

More inclined to the first writing, can walk the hash can also walk nl, the second writing small amount of data is no problem, when data volume assembly performance problems,

CodePudding user response:

This is a problem about the link table more, give it a try "how to optimize performance of the JOIN" this article can help you
  • Related