kdb+ join on different column names - Kdb+ / qStudio

Home Forums Kdb+ / qStudio kdb+ join on different column names

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #429

    Sahid
    Guest

    If I wish to join two tables on column names that are different what can I do?

    #497

    Most joins in kdb+ rely on column names matching, the easiest way would be to rename the columns.
    e.g.

    q)t:([] a:1 2 3; b:4 5 6; c:7 8 9)
    q)u:([A:1 3] uval:`ppp`ooo)

    q)t
    a b c
    —–
    1 4 7
    2 5 8
    3 6 9

    q)u
    NA| uval
    –| —-
    1 | ppp
    3 | ooo

    q)t lj u
    k){$[$[99h=@t:v y;98h=@. t;0];[n:#+!y;n!x 0!y];x y]}
    ‘NA
    @
    ,\:[;(+(,`NA)!,1 3)!+(,`uval)!,`ppp`ooo]
    +`a`b`c!(1 2 3;4 5 6;7 8 9)
    q.Q))\
    q)
    q)t lj `a xcol u
    a b c uval
    ———-
    1 4 7 ppp
    2 5 8
    3 6 9 ooo

    More information on kdb+ joins can be found at:
    http://www.timestored.com/kdb-guides/qsql-inner-left-joins

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘kdb+ join on different column names’ is closed to new replies.