Search code examples
kdb+k

Remove extra duplicate entries in unkeyed table


I have the following table below and would like to delete all rows that are duplicates. I have created a column dup which counts the number of duplicates.

delete from table where dup>1 would delete all entries of the duplicate and I would still like 1 entry to remain in my table.

ISIN         RIC      BLOOMBERG dup
-----------------------------------
LU1681046006 CWEm.BS  CWEM EB   2
LU1681046006 CWEm.BS  CWE EB    2
LU1681046006 CWEm.BS  CWEM EB   2
LU1681046006 CWEm.BS  CWE EB    2
LU1681046006 CWEm.CHI CWEM IX   2
LU1681046006 CWEm.CHI CWE IX    2
LU1681046006 CWEm.CHI CWEM IX   2
LU1681046006 CWEm.CHI CWE IX    2
LU1681046006 CWE.MI   CWE IM
LU1681046006 WDNR.DE  WDNR GY

So the resulting table should look like:

ISIN         RIC      BLOOMBERG dup
-----------------------------------
LU1681046006 CWEm.BS  CWEM EB   2
LU1681046006 CWEm.BS  CWE EB    2
LU1681046006 CWEm.CHI CWEM IX   2
LU1681046006 CWEm.CHI CWE IX    2
LU1681046006 CWE.MI   CWE IM
LU1681046006 WDNR.DE  WDNR GY

Any idea how I can achieve this?


Solution

  • Try distinct <table name>

    This should return you all of the distinct rows of your table

    For more info please reference to this link: https://code.kx.com/q/ref/search/#distinct