tags:

views:

54

answers:

3

I want to write a SQL statement something like

  insert into mytable column1=value1
 and 
((column2,column3,column4) 
(select filed1, filed2,filed3 
from anothertable where filed4=a_varible))

I am using Mysql. The statement above only expresses what I am going to achieve. Is it possible? Is there a way to achieve this?

A: 

use nested queries..........

search for nested SQL queries

Ankit Sachan
not quite an answer...
thephpdeveloper
+1  A: 

You can do that with INSERT INTO, for example:

insert into mytable
(column1, column2, column3, column4)
select 'value1', filed1, filed2, filed3 
from anothertable 
where filed4 = 'some value'
Andomar
+4  A: 

You might want something like this:

Insert Into mytable(column1,column2,column3,column4)
Select 'value1',filed1, filed2,filed3 from anothertable where filed4=a_varible

You can include a hard coded value in your select clause and it will select that as a constant for each row.

brendan