sql - MYSQL: create an insert with data from two subqueries -
i know can use subquery make insert after selecting rows database.
insert wp_43_term_relationships (object_id, term_taxonomy_id, term_order) select id, 8363, 0 ( select distinct wp_43_posts.id wp_43_posts inner join wp_43_term_relationships on wp_43_term_relationships.object_id = wp_43_posts.id inner join wp_43_term_taxonomy on wp_43_term_taxonomy.term_taxonomy_id = wp_43_term_relationships.term_taxonomy_id (wp_43_term_taxonomy.term_id = 4613 or wp_43_term_taxonomy.term_id = 4615) , wp_43_term_taxonomy.term_id != 8363 ) posts
but if, instead of hardcoding 8363, i'd need derive query?for example i'd need deriv from
select wp_43_term_taxonomy.term_taxonomy_id wp_43_term_taxonomy wp_43_term_taxonomy.term_id = 8363
if replace constant second query in ()'s, should work. this:
insert wp_43_term_relationships (object_id, term_taxonomy_id,term_order) select id, (select wp_43_term_taxonomy.term_taxonomy_id wp_43_term_taxonomy wp_43_term_taxonomy.term_id = 8363), 0 ... remaining of original ...
at least if need 1 value, otherwise better join table others.
Comments
Post a Comment