merge()

Read(310) Label: merge,

Here’s how to use merge() function.

A .merge()

Description:

Merge multiple table sequences/record sequences.

Syntax:

A.merge (xi,…)

Note:

The function merges multiple table sequences/record sequences A(i)s (which can be represented as A(i)|…) according to the rules of r.v() function when parameter xi is omitted and primary keys are not set for A, a sequence of table sequences/record sequences. Every A(i) must be of the same structure.

Parameters:

A

Multiple table sequences/record sequences of the same structure

xi

A field of A(i); if performing merge by multiple fields, use the comma to separate them, for example, x1,x2...

Options:

 

@u

Remove the duplicates from the table sequence/record sequence generated from unioning members of A(i)s in certain order

 

@i

Return a table sequence/record sequence composed of the common members of A(i)s

 

@d

Generate a new table sequence/record sequence by removing members of A(2)&…A(n) from A(1).

@o

Do not assume that A(i) is already sorted by [xi,…]

@0

Put records with null values at the end

@x

Remove common members of A(i) and union the other members to generate a new table sequence/sequence

Return value:

Table sequence/record sequence

Example:

 

A

 

1

=demo.query("select EID,NAME,GENDER,SALARY from EMPLOYEE where EID<6")

 

EID field is ordered

2

=demo.query("select EID,NAME,GENDER,SALARY from EMPLOYEE where EID>3")

EID field is ordered

3

=[A1,A2].merge(EID)

 

Merge A1 and A2 in order by EID field

4

=[A1,A2].merge@u(EID)

Merge A1 and A2 in order by EID field and remove duplicates from the result

5

=[A1,A2].merge@i(EID)

Merge A1 and A2 in order by EID field but only keep records that have duplicates

6

=[A1,A2].merge@d(EID)

Delete A2’s members from A1

7

=[A1,A2].merge@o(SALARY)

8

=[A1,A2].merge@x(EID)

Merge A1 and A2 to get a new sequence by removing their common members

9

=demo.query("select * from EMPLOYEE where GENDER = 'M'").keys(EID)

10

=demo.query("select * from EMPLOYEE where GENDER = 'F'").keys(EID)

11

=[ A9,A10].merge()

With xi omitted, this table sequence is the result of merge by the order of the primary keys

12

=demo.query("select * from EMPLOYEE where GENDER = 'M' and EID<15")

 

13

=demo.query("select * from EMPLOYEE where GENDER = 'M' and EID>=15")

 

14

=[A12,A13].merge(EID,GENDER)

Merge by the EID field and GENDER field

15

=A1.run(EID=null)

 

16

=[A2,A15].merge(EID)

17

=[A2,A15].merge@0(EID)

Related functions:

  CS.mergex()