q kdb+ finding index of match elements using a list

811 views Asked by At

Say I have a list

b:1 1 2 3 4

and I want to find the location of the element in list b using another list

a:1 2

When I type in b in\ a, I got

11000b
00000b

where it should be

11000b
00100b

What is going on and how to get the desired answer?

Thanks in advance!

2

There are 2 answers

0
Thomas Smyth - Treliant On

You need to use each-right /:

q)b in/:a
11000b
00100b

With b in\a the first output is getting passed back in as b. Effectively:

q)1 1 2 3 4 in 1
11000b
q)11000b in 2
00000b
0
AudioBubble On

You can also use each-both ':

q)in[b]'[a]
11000b
00100b