Using a value in a 'like'

22 views
Skip to first unread message

Kevin Jones

unread,
Jul 14, 2023, 12:32:08 PM7/14/23
to jOOQ User Group
I have SQL something like this

SELECT * from A 
join B on A.Name like CONCAT ('%', B.Name, '%")

Is that possible in JOOQ?

Thanks,

Kevin

Alf Lervåg

unread,
Jul 14, 2023, 2:06:14 PM7/14/23
to jooq...@googlegroups.com
I don’t have my computer handy, but yes thats pretty simple in jOOQ. Something close to:

ctx
.selectFrom(A)
.join(B)
.on(A.Name.like(concat(inline('%'), B.Name, inline('%')));

Note that it is unlikely that your database will be able to use an index for this join, so be certain your datasets don’t grow too big here or you’ll have bad performance.

Alf Lervåg

14. jul. 2023 kl. 18:32 skrev Kevin Jones <ke...@knowledgespike.com>:

I have SQL something like this
--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jooq-user/b22e6d9d-49ab-4cc9-aa57-12ba3e61cbbfn%40googlegroups.com.

Kevin Jones

unread,
Jul 14, 2023, 5:00:35 PM7/14/23
to jOOQ User Group
Thank you,

I was missing the 'inline'

Kevin

Alf Lervåg

unread,
Jul 14, 2023, 5:47:51 PM7/14/23
to jooq...@googlegroups.com
You could also have used val, but in this case I believe inline is correct. 

Alf Lervåg

14. jul. 2023 kl. 23:00 skrev Kevin Jones <ke...@knowledgespike.com>:

Thank you,

Lukas Eder

unread,
Jul 17, 2023, 3:28:25 AM7/17/23
to jooq...@googlegroups.com
Hi Kevin,

In addition to Alf's suggestion, you could also just use Field.contains(Field)

I hope this helps,
Lukas

--
Reply all
Reply to author
Forward
0 new messages