We help IT Professionals succeed at work.

MySQl - get record id from one table and insert into another?

sabecs
sabecs used Ask the Experts™
on
Hi, how can I get the id's from the table `users` and insert them into the `user_upd_tags` ?


CREATE TABLE IF NOT EXISTS `users` (
  `id` int(6) NOT NULL auto_increment,
  `sess_id` varchar(50) default NULL,
  `session_last_active` int(11) default '0',
  `updated` int(1) default '0',
  `last_updated` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  `date_joined` int(11) default NULL,
  `username` varchar(20) default NULL,
  `password` varchar(20) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `id` (`id`),
  KEY `member_type` (`member_type`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 PACK_KEYS=0 AUTO_INCREMENT=545 ;

CREATE TABLE IF NOT EXISTS `user_upd_tags` (
  `user_id` int(11) default NULL,
  `updated` int(1) default '0',
  `tags` text,
  KEY `user_id` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Web Application Programmer
Commented:
Since you have this in the JavaScript zone I assume you trying to do this with JavaScript? if you do, the answer is you can't.
Database related operations should be performed using proper programming language like PHP, C#, Java or something in that line.
However, You can setup the database manipulation code in such language and call them over the web using JavaScript (AJAX).

Also, I might be totally off track above, and maybe you are looking for something like:
INSERT INTO `user_upd_tags` (`user_id`, `updated`, `tags`)
SELECT `id`, 0, '' FROM `users`

Open in new window

Author

Commented:
Thanks sudaraka, yes sorry, I meant to put in MySQL zone...
Tahnks again for your help..
Sudaraka WijesingheWeb Application Programmer

Commented:
Glad to help. Thanks for the points.