INSERT Into with Order by
DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: INSERT Into with Order by

  1. #1
    Join Date
    Dec 2000
    Posts
    6
    I want to do the following:
    INSERT INTO TableA
    Select * from TableB
    Order by TableB.FieldA

    How do I do this??!!

  2. #2
    Join Date
    Nov 2000
    Location
    greenwich.ct.us
    Posts
    9,092
    You can't use order by in an insert statement:
    jeff@dev815nt.us> insert into table_b select * from table_a
    2 order by 1
    3 /
    order by 1
    *
    ERROR at line 2:
    ORA-00933: SQL command not properly ended


    jeff@dev815nt.us> desc table_a
    Name Null? Type
    ----------------------------------------- -------- ----------------------------
    D VARCHAR2(20)
    E DATE
    F VARCHAR2(20)

    jeff@dev815nt.us> drop table table_b;

    Table dropped.

    jeff@dev815nt.us> create table table_b as select * from table_a order by d;

    Table created.

    jeff@dev815nt.us> select * from table_b;

    D E F
    -------------------- --------- --------------------
    3607551298 30-JAN-50 3111188
    3607551428 30-JAN-50 2160118
    3607551428 30-JAN-50 2160118
    3607551428 30-JAN-50 2160118
    3607551484 30-JAN-50 3934798
    3607551484 30-JAN-50 3934798
    3607551484 30-JAN-50 3934798

    7 rows selected.

    jeff@dev815nt.us> select * from table_a
    2 /

    D E F
    -------------------- --------- --------------------
    3607551428 30-JAN-50 2160118
    3607551484 30-JAN-50 3934798
    3607551428 30-JAN-50 2160118
    3607551484 30-JAN-50 3934798
    3607551298 30-JAN-50 3111188
    3607551428 30-JAN-50 2160118
    3607551484 30-JAN-50 3934798

    7 rows selected.
    Jeff Hunter
    marist89@yahoo.com
    http://marist89.blogspot.com/
    Get Firefox!
    "I pledge to stop eating sharks fin soup and will not do so under any circumstances."

  3. #3
    Join Date
    Jul 2000
    Posts
    296
    In 8.1.6 you can use ORDER BY in (inline) views, and
    INSERT INTO tab_a
    SELECT * FROM tab_b
    ORDER BY col_c
    will work.

    But why do you want such an insert? You cannot be sure that if you try
    SELECT * FROM tab_a
    it will be ordered on col_c.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width