0

I need to fetch max(date) from another table while inserting a record in present table here is my query

insert into table2 values (null,12,(select max(odate) from table1),0)

this code doesn't seem to work please help

Dharman
  • 30,962
  • 25
  • 85
  • 135
Daniel Euchar
  • 1,740
  • 5
  • 28
  • 45
  • In you code all date value for all the records is going to be same – R D Jun 30 '14 at 11:28
  • http://stackoverflow.com/questions/74162/how-to-do-insert-into-a-table-records-extracted-from-another-table – R D Jun 30 '14 at 11:28

1 Answers1

2

Use insert . . . select instead of insert . . . values:

insert into table2 
    select null, 12, max(odate), 0
    from table1;

As a note: you should get in the habit of including the column names in the insert() statement.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786