chrise
chrise

Reputation: 4253

KDB select where x in other query result

I have a query

top:flip select [10] Name from `Val xdesc select sum Val by Name from table

and I want another query filtering based on that result

select from table where Name in top

however that gives me a type error. I also tried

select from table where {x in y}[Name; top]

but that yields an empty table. Any suggestions how this can be done?

Upvotes: 0

Views: 1836

Answers (1)

James Little
James Little

Reputation: 2069

The second parameter to in needs to be of list type, so you could do:

select from table where Name in exec Name from top

or:

select from table where Name in top[`Name]

You could also make top a list to begin with. Using the take operator to get the first 10 items in the sorted table:

top:10#(exec Name from `Val xdesc select sum Val by Name from table)

and then you would be able to do:

select from table where Name in top

Upvotes: 2

Related Questions