Have a problem with update some rows in table 'commission'. Now I have commission_number like bar/123/456. I'd like to rename it to John/123/456 etc, taking a name from 'user' table
commission user
------------------------- -----------------
commission_number|user_id username|user_id
------------------------- -----------------
bar/123/456 | 1 John | 1
bar/123/123 | 2 Bob | 2
bar/456/123 | 3 Thomas | 3
Below is my query, working with 'baz'. But don't know how to place 'username' from 'user' table. I only need to replace 'baz', and use username from 'user', but don,t know how.
UPDATE commission
SET commission_number = overlay(commission_number placing 'baz' FROM POSITION('bar' IN commission_number) for 3)
WHERE commission_number in (1,2,3,4,5,6,7,8)