Jump to content

insert into one table using info from another?


onedumbcoder

Recommended Posts

lets say I want to insert into table a six values, 3 of those values need to come from table b.

 

so is there a way I can do this?

 

in my example

 

insert into a(1,2,3,4,5,6) values((Select a,b,c from b WHERE id=1),"he","hy","hu")

 

I want (Select a,b,c from b WHERE id=1) to be treated as three values if possible, so it would ultimately translate

 

values((Select a,b,c from b WHERE id=1),"he","hy","hu") as values(a,b,c,"he","hy","hu")

 

Huh? What do you want the records to look like in the end?

1-6 are just examples,

 

lets say I have a table food with the fields  name, id, date, creator, country, size

 

so i want to make an insertion

 

insert into food(name,id,date,creator,country,size) values((SELECT name,id,date FROM food WHERE id=3),"mike","usa","5")

Thanks zanus that is what I needed.

 

Another question you know how there is

 

INSERT INTO a(b) VALUES© WHERE NOT EXIST (SELECT id FROM ww WHERE id=1)

 

can I do

 

INSERT INTO a(b) VALUES© WHERE EXIST (SELECT id FROM ww WHERE id=1)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.