oracle8.1.6 select sort_key as other_sort_key, element_id as other_element_id from (select * from layout_elements where page_id = :page_id and page_column = :page_column and sort_key < :sort_key order by sort_key desc) where rownum = 1 select sort_key as other_sort_key, element_id as other_element_id from (select * from layout_elements where page_id = :page_id and page_column = :page_column and sort_key > :sort_key order by sort_key asc) where rownum = 1 update layout_elements set page_column = :page_column, sort_key = (select nvl((select max(sort_key) + 1 from layout_elements where page_id = :page_id and page_column = :page_column), 1) from dual) where element_id = :element_id update layout_elements set page_id = :page_id, page_column = :page_column, sort_key = (select nvl((select max(sort_key) + 1 from layout_elements where page_id = :page_id and page_column = :page_column), 1) from dual) where element_id = :element_id