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 query to take three OPTIONAL id's for example I would like the query to ultimately be
select * from my_table where ID1=5 and ID2=6 and ID3=7 .... etc
However, I would also like the option of being able to exclude any of the id's
select * from my_table where ID2=6 and ID3=7
or
select * from my_table where ID3=7
The problem with this is that the first "where" clause belongs to id one and the rest are ands so if I did an if statement and I removed the where then I would just be left 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 wouldn't work.
I tried to look for something like where id = *
where * is essentianlly no filter but I couldn't find anything like that.