Jump to content

Insert select query help


samoht

Recommended Posts

hello all,

 

I need to run a query of one table to get all on my records that I need to insert a row for in another table.

the table that I first need to query has all my post ID's that have the category 104 the table structure is as follows:

`wp_term_relationships` (

  `object_id` bigint(20) unsigned NOT NULL default '0',

  `term_taxonomy_id` bigint(20) unsigned NOT NULL default '0',

  `term_order` int(11) NOT NULL default '0',

  PRIMARY KEY  (`object_id`,`term_taxonomy_id`),

  KEY `term_taxonomy_id` (`term_taxonomy_id`)

 

the table I need to insert into is as follows:

`wp_postmeta` (

  `meta_id` bigint(20) unsigned NOT NULL auto_increment,

  `post_id` bigint(20) unsigned NOT NULL default '0',

  `meta_key` varchar(255) default NULL,

  `meta_value` longtext,

  PRIMARY KEY  (`meta_id`),

  KEY `post_id` (`post_id`),

  KEY `meta_key` (`meta_key`)

) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=22446 ;

 

As noted above I want to query wp_term_relationships for all the records (object_id's) that have a "term_taxonomy_id" = 104 then Insert into wp_postmeta a post_id that matches the object_id and a meta_key that = "amprotect_amproducts" and a meta_value that = "a:6:{i:13;s:1:"1";i:6;s:1:"1";i:14;s:1:"1";i:7;s:1:"1";i:8;s:1:"1";i:1;s:1:"1";}"

 

Any Ideas who to do this??

 

I was thinking

INSTER INTO wp_postmeta ('object_id', 'amprotect_amproducts','')SELECT object_id FROM wp_term_relationships WHERE term_taxonomy_id = 104

 

Thanks,

Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.