4

I want to do something like this:

INSERT INTO temp_table (temp_value) VALUES ( SELECT source_value FROM the_table WHERE condition_value = some_value ) WHERE temp_condition = some_value_condition

Do you guys know a way of doing this?

Any advice is appreciated

Annatar
  • 87
  • 6
  • Never mind, I just had a _lapsus brutus_ and was trying to use `INSERT INTO` instead of UPDATE. – Annatar Feb 20 '14 at 21:42

3 Answers3

0

you do not need the values keyword

INSERT INTO mytable( aa,bb,cc )
SELECT a,b,c FROM xyz
Randy
  • 16,480
  • 1
  • 37
  • 55
0
INSERT INTO temp_table (temp_value)  SELECT source_value FROM the_table WHERE condition_value = some_value  And temp_condition = some_value_condition
Random
  • 467
  • 1
  • 4
  • 9
0

You can try some like this basic structure

INSERT INTO temp_table (Value1,Value2,Value3) 
SELECT field1, field2, field3 
FROM the_table 
WHERE condition_value = some_value 

Remember have the same number of fields in your INSERT INTO and your SELECT.

Ayan Sengupta
  • 5,238
  • 2
  • 28
  • 40
pasachova
  • 56
  • 5