Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: SQL question
R Fray wrote:
> I can't use :
> insert into table1 (select max(value) from table2 where a=b);
>
> Because 'value' can be the same in more than one instance, hence using
> max does not weed out duplicated.
select max() will return only one value, even if there is more than one
occurance of that value. You'll only get multiple values from a select
with aggregates (man(), min(), avg(), etc...) if you have a GROUP BY
clause in your select.
And you don't.
So you won't.
> Is there something equivalent to :
> insert into table1 (select first(value) from table2 where a=b);
>
> So that I can select the first instance and ignore all others?
You could also add "AND ROWNUM = 1" to your where clause. But the MAX() example you gave should work. It shouldn't give you a 1427. It may give you a dupe values error if it's already on table1 and violates a unique/primary key constraint.
--
Adrian Hands
Raleigh, NC
panic: attempt to recv circular datagram in round socket!
panic: stack pointer is read-only!
$
Received on Wed Sep 16 1998 - 23:45:15 CDT