On Thu, 3 Apr 2008, Johan Höök wrote:

Hi Hiep,
you can put in either xxx = NULL
or you can skip it completely:
insert into tbl_1(fld2,fld3) select fld_b, NOW() from tbl_2;

Regards,
        /Johan

Hiep Nguyen skrev:

hi all, i have a question on insert ... select statement.

tbl_1(fld1,fld2,fld3, ....)

fld1 int primary key auto_increment not null

tbl_2(fld_a,fld_b,fld_c,...)

how do i construct my select statement so that fld1 is auto increment?

insert into tbl_1(fld1,fld2,fld3) select xxx, fld_b, NOW() from tbl_2 where fld_a = '5';

what should 'xxx' be???

my goal is to get

fld1 = auto increment
fld2 = fld_b
fld3 = NOW()


i saw someone used '1', other used null for xxx.  i'm confused.

thanks.
t. hiep


insert into tbl_1(fld1,fld2,fld3) select NULL,fld_b, NOW() from tbl_2 where fld_a = '5' limit 1;


how do i prevent the insertion when select returned empty record?

thanks,
t. hiep
-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to