insert question..

Started by Williams, Travis L, NPONSalmost 23 years ago4 messagesgeneral
Jump to latest

I'm looking for an example on how to insert static data and information from a select at the same time..

currently I'm doing:

insert into performance (start,finish) select min(poll_time),max(poll_time) from poll

I need to add a 3rd field that is static so I would have something like this

insert into performance (name,start,finish) travis,select min(poll_time),max(poll_time) from poll

Thanks,

Travis

#2Thomas Kellerer
spam_eater@gmx.net
In reply to: Williams, Travis L, NPONS (#1)
Re: insert question..

Williams, Travis L, NPONS schrieb:

I'm looking for an example on how to insert static data and information from a select at the same time..

currently I'm doing:

insert into performance (start,finish) select min(poll_time),max(poll_time) from poll

I need to add a 3rd field that is static so I would have something like this

insert into performance (name,start,finish) travis,select min(poll_time),max(poll_time) from poll

insert into performance (name,start,finish)
select 'Travis', min(poll_time),max(poll_time) from poll

Cheers

#3Bruno Wolff III
bruno@wolff.to
In reply to: Williams, Travis L, NPONS (#1)
Re: insert question..

On Wed, Jun 11, 2003 at 10:45:05 -0400,
"Williams, Travis L, NPONS" <tlw@att.com> wrote:

I'm looking for an example on how to insert static data and information from a select at the same time..

currently I'm doing:

insert into performance (start,finish) select min(poll_time),max(poll_time) from poll

I need to add a 3rd field that is static so I would have something like this

insert into performance (name,start,finish) travis,select min(poll_time),max(poll_time) from poll

If travis is really a constant then you could do:
insert into performance (name,start,finish)
select 'travis', min(poll_time), max(poll_time) from poll;

Another option that might be faster (if there is an index on poll_time)
because you are using max and min is:
insert into performance (name,start,finish)
values ('travis',
(select poll_time from poll order by poll_time limit 1),
(select poll_time from poll order by poll_time desc limit 1))

#4Dmitry Tkach
dmitry@openratings.com
In reply to: Williams, Travis L, NPONS (#1)
Re: insert question..

Williams, Travis L, NPONS wrote:

I'm looking for an example on how to insert static data and information from a select at the same time..

currently I'm doing:

insert into performance (start,finish) select min(poll_time),max(poll_time) from poll

I need to add a 3rd field that is static so I would have something like this

insert into performance (name,start,finish) travis,select min(poll_time),max(poll_time) from poll

Almost :-)

The correct syntax is:

insert into performance (name,start,finish) select 'travis', min(poll_time),max(poll_time) from poll;

I hope, it helps.

Dima