Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- KX Community
- :
- Discussion Forums
- :
- kdb+ and q
- :
- Re: idistinct

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

idistinct

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2018.06.19 03:19 AM

q)show t:([]a:1 1 1;b:1 2 2;c:`a`b`c)

a b c

-----

1 1 a

1 2 b

1 2 c

q)distinct select a,b from t

a b

---

1 1

1 2

but need to incorporate the c column so the result i want might be

a b c

------

1 1 a

1 2 b

so an idistinct would be helpful à la iasc:

q)t idistinct select a,b from t

a b c

------

1 1 a

1 2 b

can idistinct or other useful function be built with similar performance to distinct?

thanks guys.

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2018.06.20 07:08 AM

q)select from t where i=(first;i)fby ([]a;b)

a b c

-----

1 1 a

1 2 b

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2018.06.20 07:22 AM

you can implement idistinct with the find operator

q)idistinct:{x?distinct x}

q)t idistinct select a,b from t

a b c

-----

1 1 a

1 2 b

Abdul

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2018.06.20 08:04 AM

select by a,b from t

This will return last row for each a,b distinct combination.

Or if you want first entry, you can use:

select first c by a,b from t

This gives some performance improvement over fby but if you have fat table and require many columns into output then fby makes that job easy.

On Wednesday, 20 June 2018 14:54:15 UTC+1, effbiae wrote:

q)show t:([]a:1 1 1;b:1 2 2;c:`a`b`c)a b c-----1 1 a1 2 b1 2 ci can find distinct rows considering a,b byq)distinct select a,b from ta b---1 11 2but need to incorporate the c column so the result i want might bea b c------1 1 a1 2 bso an idistinct would be helpful à la iasc:q)t idistinct select a,b from ta b c------1 1 a1 2 bcan idistinct or other useful function be built with similar performance to distinct?thanks guys.

Main Office Contacts

**EMEA**

Tel: +44 (0)28 3025 2242

**AMERICAS**

Tel: +1 (212) 447 6700

**APAC**

Tel: +61 (0)2 9236 5700

Useful Information

Popular Links

Follow Us

KX. All Rights Reserved.

KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.