Reputation: 61
I have a table of data in kdb and I would like to use q to remove the rows which contain a duplicate value in one column.
For example, if I have the following table where there is a duplicate value in the Age
column:
Name Age Degree
---------------------
Alice 26 Science
Bob 34 Arts
Carrie 26 Engineering
How would I delete the third row so I end up with the following:
Name Age Degree
---------------------
Alice 26 Science
Bob 34 Arts
Thanks!
Upvotes: 1
Views: 1029
Reputation: 31
You can delete any of the duplicates in any columns using this:
q)delete from t where ({not x in 1#x};i) fby Age
Name Age Degree
-----------------
Alice 26 Science
Bob 34 Arts
Could also be solved using a by clause instead of fby, but in this case to get the first occurrence of each age you have to use reverse
q)0!select by Age from reverse t
Age Name Degree
-----------------
26 Alice Science
34 Bob Arts
Upvotes: 3