I have created a relation
table1.field1 = table2.field1
table1.field2 = table2.field2
table1.field3 ^||= table2.field3
table1.field4 ^||= table2.field4
if for example table1.field4 and table2.field4 are both null then the relation doesn’t find any data.
select
Table2.Table2_id
from
Table2
where
(Table2.Field1 = ?
and Table2.Field2 = ?
and (Table2.Field3 = ?
or Table2.Field3 is null)
and (Table2.Field4 = ?
or Table2.Field4 is null))
order by
Table2.Table2_id asc
for Table2.find()
select
Table2.Table2_id
from
Table2
where
(Table2.Field3 is null
or Table2.Field3 = ?)
and Table2.Field2 = ?
and (Table2.Field4 is null
or Table2.Field4 = ?)
and Table2.Field1 = ?
order by
Table2.Table2_id asc
select
Table2.Table2_id
from
Table2
where
(Table2.Field3 is null
or Table2.Field3 = ?)
and Table2.Field2 = ?
and Table2.Field4 is null
and Table2.Field1 = ?
and (Table2.Field3 is null
or Table2.Field3 = ?)
and Table2.Field2 = ?
and Table2.Field4 is null
and Table2.Field1 = ?
order by
Table2.Table2_id asc