Home > database >  How to don't union all vertical splicing two fields of a table
How to don't union all vertical splicing two fields of a table

Time:03-03

If the use union all the forms are as follows:
Select a from a
Union all
Select b from A
So no problem, but there are hidden dangers, performance is essentially will scan A table, two logical reads will surge and multiplying, but if you select A, b from A multiple consumption performance will reduce, and in fact have been read to A and b, is there any way to read only once A table to realize the union under the condition of all the vertical stitching way? Or better than union all performance, also there are several dozens of union all are now facing is, data is merged the same associative table of the same type, individual table data volume millions, with the union all performance is slow,

CodePudding user response:

Values can be used

CodePudding user response:

 
The SELECT tt. Val
The FROM (SELECT 10 AS A, 20 B AS the UNION ALL SELECT 30, 40) t
OUTER APPLY (SELECT * FROM (VALUES (t.A), (t.B)) x (val)) tt;

CodePudding user response:

Transfer line column unpivot know about the
Select * from table
UNPIVOT
(
X FOR y IN (field 1, 2, field 3, field 4)
)p

CodePudding user response:

The
reference sleet reply: 3/f
row transfer column unpivot know about the
Select * from table
UNPIVOT
(
X FOR y IN (field 1, 2, field 3, field 4)
) p

I think so, too, at first, but after tried, found that in the back of the field has a hidden too strict restrictions, in addition to the same type also must be exactly the length or type error, it is quite troublesome, moderators to above method is no this requirement,
  • Related