get rows from a table by distinct column values

I want to extract rows from a table with distinct entries for a column and taking first/last values of other columns for each value of the unique column.

For example

q)t1:(c1:1 2 3 4; c2:sym?cba`c)

q)t1

c1 c2


1  c

2  b

3  a

4  c

In this case, I want the following result -

c1 c2


2 b

3 a

4 c

I am doing this but its not working -

q)xcols[cols t1; select by c2 from t1]

'length

c1c2

(+(,c2)!,sym$abc)!+(,c1)!,3 2 4

Not sure what this error means.

xcols only works on unkeyed, so

q)cols[t1]xcols 0!select by c2 from t1

c1 c2


3  a 

2  b 

4  c 

Cheers,

  Attila

Oh yes ofcourse. Thanks!

Btw to get the first entry  for each value of unique column, we can do this -

cols[t1]xcols 0!select first c1 by c2 from t1