mysql - Join Two Tables and Replace Values Where Conditions Meet -
i'm trying come expression join 2 tables (the first two) third one.
i want select 'sitepage' , 'medium' , join first 2 tables on rows right 5 characters matching between 'sitepage' , 'campaign id'. additionally, if there match, 'program' replace 'medium'. syntax?
sitepage | medium xyz.com/campaign=12345 | xyz.com/campaign=23456 | c campaign id | program 12345 | b sitepage | medium xyz.com/campaign=12345 | b xyz.com/campaign=23456 | c
i based answer off of @juan's, had make adjustments work.
select sitepage, coalesce(t2.program, t1.medium) medium table1 t1 left join table2 t2 on right(t1.sitepage, 5) = coalesce(t2.`campaign id`, -1);
@abhik heading in right direction too. it's more generic 1 above, assumes last 5 characters of sitepage
pertinent ones. said, have gone with...
select sitepage, coalesce(t2.program, t1.medium) medium table1 t1 left join table2 t2 on substring_index(t1.sitepage,'=',-1) = coalesce(t2.`campaign id`, -1);
Comments
Post a Comment