MySQL JOIN two tables using LIKE and substrings -
i have been trying join 2 mysql tables columns contain common substring.
my first table trim_table data set of substrings , id. each row contains id, , substring such "1717 winton dr".
the second table wp_prop contains columnfield_313 may contain substring found on first table. example value of field_313 "the sargent iii @ 1717 winton dr"
the following query formulated join both tables:
select *, wp_prop.id prop_id, trim_table.id post_id, wp_prop.field_313 prop_name, trim_table.trim_value post_name (select id, trim(substring(post_title, locate('@', post_title)+1)) trim_value wp_nd333j_posts post_type="fplan") trim_table join wp_nd333j_wpl_properties wp_prop on trim_table.trim_value concat('%', wp_prop.field_313, '%') unfortunately, query not return rows. have decomposed query different parts verify work.
it substring dataset returns correct rows executing following query:
select * (select id, trim(substring(post_title, locate('@', post_title)+1)) trim_value wp_nd333j_posts post_type="fplan") trim_table i can verify wp_prop table contains substring similar example posted above executing following query:
select * wp_nd333j_wpl_properties wp_prop field_313 "%1717 winton dr%" i verified substring dataset contains desired substring executing query:
select * (select id, trim(substring(post_title, locate('@', post_title)+1)) trim_value wp_nd333j_posts post_type="fplan") trim_table trim_value = "1717 winton dr"
you have switch fields in on clause:
on wp_prop.field_313 concat('%', trim_table.trim_value, '%') http://sqlfiddle.com/#!9/616a0/1
select trim_table.id post_id, trim_table.trim_value post_name, wp_prop.id prop_id, wp_prop.field_313 prop_name ( select id, trim(substring(post_title, locate('@', post_title)+1)) trim_value wp_nd333j_posts post_type="fplan" ) trim_table inner join wp_nd333j_wpl_properties wp_prop on wp_prop.field_313 concat('%', trim_table.trim_value, '%')
Comments
Post a Comment