Select distinct for all columns from keyed table

719 Views Asked by At

It seems we can not get distinct values from a keyed table in the same way as for unkeyed:

t:([a:1 2]b:3 4)
?[t;();0b;()]   // keyed table
?[0!t;();1b;()] // unkeyed table
?[t;();1b;()]   // err 'type

Why do we have this error here?

1

There are 1 best solutions below

0
terrylynch On BEST ANSWER

I suspect it's the same reason you can't run distinct on a dictionary - it's ambiguous. Do you intend to apply distinct to the keys or the values? I think kdb doesn't pick a side so it makes you do it yourself.

q)t:([]a:1 1 1 2 2;b:10 12 10 14 14)
q)select distinct from t
a b
----
1 10
1 12
2 14
q)select distinct from 1!t
'type

q)distinct `a`b`c!(1;"ab";enlist 1b)
'type