Search code examples
javasql-order-byderby

how to save "order by" table?


I want to sort my database, then save it as it is. what is the easiest way to do this? sql can be something like this:

sql = "SELECT * FROM APP." + tablename + " order by" + sql_part;

thanks.


Solution

  • you can follow the below steps

     1) create table <temp_tablename> as SELECT * FROM APP.<tablename> order by <columnname>;
     2) drop table APP.<tablename>;
     3) ALTER TABLE <temp_tablename> RENAME TO APP.<tablename>; -- Oracle
        or RENAME TABLE <temp_tablename> TO APP.<tablename>; -- DB2