Connecting Tech Pros Worldwide Help | Site Map

inserting multiple values from one table to another tables

tb1 tb1 is offline
Newbie
 
Join Date: Jan 2008
Posts: 4
#1: Jan 8 '08
Hi all,

I have these two tables

RMB with these columns RMID, RMBCD, RMCD and RMBA

OL with these columns RMID and Status.

What i want is to insert the RMID of all columns from RMB table where RMBA is under a certain value.

I was thinking something like:
INSERT INTO OL (RMID, Status) VALUES (SELECT RMID FROM RMB WHERE RMBA >='1' LIMIT 1;, ok)

however the select returns multiple columns and this will insert multiple columns from RMB into one column in OL, right?

can someone help me in the right direction?
mwasif's Avatar
Moderator
 
Join Date: Jul 2006
Location: Pakistan
Posts: 718
#2: Jan 8 '08

re: inserting multiple values from one table to another tables


Hi tb1,

Welcome to TSDN!!!

You are almost right. The exact syntax will be
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO OL (RMID)
  2. SELECT RMID FROM RMB WHERE RMBA >='1'
The above query will insert all the values of RMID where RMBA is greater than or equal to 1.

Check the MySQL Manual for more details.
tb1 tb1 is offline
Newbie
 
Join Date: Jan 2008
Posts: 4
#3: Jan 8 '08

re: inserting multiple values from one table to another tables


thx for the quick reply.
Reply