List<MyTable> result = DSL.using(configuration()) .select() .from(MY_TABLE) .where(MY_TABLE.ID1.equal(pk_id1)) .and(MY_TABLE.ID2.equal(fk_id2)) .and(MY_TABLE.ID3.equal(fk_id3)) .orderBy(MY_TABLE.ID.asc()) .limit(limit) .fetchInto(MY_TABLE) .map(mapper());
I'm trying to write some code that will allow my request to take three OPTIONAL id, for example, I would like the request to be
select * from my_table where ID1=5 and ID2=6 and ID3=7 .... etc
However, I would also like to be able to exclude any of
select * from my_table where ID2=6 and ID3=7
or
select * from my_table where ID3=7
The problem is that the first phrase "where" belongs to id one, and the rest belongs to ands, so if I made an if statement and I deleted it to where I would just stay with
List<MyTable> result = DSL.using(configuration()) .select() .from(MY_TABLE) .and(MY_TABLE.ID2.equal(fk_id2)) .and(MY_TABLE.ID3.equal(fk_id3)) .orderBy(MY_TABLE.ID.asc()) .limit(limit) .fetchInto(MY_TABLE) .map(mapper());
and it wonβt work.
I tried to find something like where id = * , where * is essentianlly there is no filter, but I could not find anything like it.
source share