tags:

views:

35

answers:

3

Hi All

I would like to do a query for inserting a value calculated starting upon another table. I don't want to use Temporary tables and I would like to do everything in one singel query. It is possible?

I tried this one below but it doesn't work.

Thanks

AFeG

INSERT INTO MyTable( `DATE`, `Name`, `Total` ) 
VALUES ( 
 '2010/01/01',
 'Thunder',
  SELECT SUM(aValue) FROM AnotherTable
)
+1  A: 

Try

insert mytable
select date
      ,name
      ,sum(total)
  from anothertable
hypoxide
+1  A: 
INSERT  
INTO    MyTable( `DATE`, `Name`, `Total` ) 
SELECT  '2010/01/01', 'Thunder', SUM(aValue)
FROM    AnotherTable
Quassnoi
A: 

If you want precisely what you indicated:

insert mytable
select 
"2010/01/01", "thunder", 
sum(mycolumn)
from othertable
Liz Albin