Forum OpenACS Development: How do I get first half rows from ORACLE table

Hello All,

  I want to take first half rows from one table and insert  them into another table.
  The structure of both tables is same.

  How can I do it ?

I have written a query like this

insert into table2(col1, col2, col3) values (select rownum<=(count(table1.col1)/2) from table1);

but it won't work

Please send me query as early as possible

Thank You in advance

Best Regards

Yogesh
Collapse
Posted by Dirk Gomez on
Why do you want to do this?
Collapse
Posted by Dirk Gomez on
If it's Oracle, you may want to look into the SAMPLE clause.
Collapse
Posted by Sebastiano Pilla on
"First half" according to what order? Unless you impose an ordering on the result set (with an "order by" clause) it's impossibile to talk about first or second, or last if that matters. Oracle manages to store data in such a way that there's no guarantee that a simple select without order by will return the data in the order that has been inserted.
Collapse
Posted by Nis Jørgensen on
So, is there any way to return a subset of the records, based on an explicit ordering? Something like mySQL's LIMIT. It seems like ROWNUM can not be used for this purpose (although I may be wrong).
Collapse
Posted by Dirk Gomez on
select * from
  (select a,b,c,rownum
  from foobar
  order by bla)
where rownum < 10

should do the trick.

insert into newly_acquired_stocks
        select * from my_stocks
        where rownum < = (select count(*)/2 from my_stocks);

this will work out check it out