The beauty of this language is exactly as Johan says, you can skip the
obvious, Just insert all the other non-obvious columns. In the event that
you have numerous defaulted columns, though, it's best to supply a NULL so
the syntax is parallel (IMO), or alternatively to name the columns. But
either way, for your auto-increment column, I would suggest skipping it
completely and just worry about the other columns. As Johan has suggested,
you can even substitute functions' return values for what you wish to
insert.

You can do almost anything you want
in the MySQL Restaurant.

A.

On Thu, Apr 3, 2008 at 10:37 AM, Johan Höök <[EMAIL PROTECTED]>
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
> >
> >
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/[EMAIL PROTECTED]
>
>

Reply via email to