KDB Query with OR condition like in SQL

3.3k views Asked by At

In SQL I may write query with logical (true and true) or (true and true), i.e:

select * from t1 inner join t2 on ... where (t1.a != t2.a and t1.b != t2.b) or (t1. != t2.a and t1.b != t2.b)

when I try to do it in Q like this

select from ej[....] where (t1.a != t2.a and t1.b != t2.b) or (t1. != t2.a and t1.b != t2.b)

it fails to compile.

I have also tried this

(t1.a != t2.a and t1.b != t2.b) or (t1. != t2.a and t1.b != t2.b)

but it doesn't return the correct result either

How to query it in KDB?

1

There are 1 answers

0
terrylynch On

Try this (in pseudo-code):

( (t1.a != t2.a) and (t1.b != t2.b) ) or ( (t1.a != t2.a) and (t1.b != t2.b) )

Kdb/Q reads left-of-right so it treats

t1.a != t2.a and t1.b != t2.b

as

t1.a != (t2.a and t1.b != t2.b)

rather than

(t1.a != t2.a) and (t1.b != t2.b)

unless you explicity use brackets