KDB get only the rows present only in one table

Viewed 147

I have two tables table1 and table2. Both has 4 columns with same column names. table1 has 50 rows and table2 has 100 rows. How can I get only those rows from table2, which are not there in table1. I tried performing left join, but I am not able to do that, since we can't do left join using all columns.

1 Answers

Since tables are lists of dictionaries, you could use the except keyword to exclude all rows from table2 which are found in table1.

For example:

q)table1:([]a:til 3;b:3#.Q.a;c:3#.Q.A)
q)table1
a b c
-----
0 a A
1 b B
2 c C

q)table2:([]a:til 6;b:6#.Q.a;c:6#.Q.A)
q)table2
a b c
-----
0 a A
1 b B
2 c C
3 d D
4 e E
5 f F

q)table2 except table1
a b c
-----
3 d D
4 e E
5 f F
Related