KDB query for OR operator

What is an equivalent query in KDB Web:

SELECT * FROM TABLE
WHERE (COLA = 'A' AND COLB = 'B') OR (COLA = 'C' AND COLB = 'D')

http://kdbserver:5001/?select fro table where _____________________

NB: cola and colb have a string data type

+4
source share
4 answers

You can do:

select from table where ((COLA like "string1")&(COLB like "string2"))|((COLA like "string3")&(COLB like "string4"))
+6
source
select from table where ([]colA;colB) in ([]colA:`A`C;colB:`B`D)
+3
source

Connor is right, and his answer is quite effective. I just want to add a version with a list instead of a table:

tab:([]cola:("aaa";"bbb";"ccc");colb:("ddd";"eee";"fff"))
select from tab where (flip(cola;colb))in\:(("aaa";"ddd");("bbb";"eee"))

Run speed is almost identical to Connor one

+1
source

Sometime I prefer to change type to character to get results,
say,

tab1:([]a:string 10?`2;b:string 10?`2; c: string 10?`2)  

-

select from tab1 where (((`$a)=`$"ci") & ((`$b)=`$"lf")) or (((`$a)=`$"en") & ((`$b)=`$"dl"))  
0
source

All Articles