select count(*) from ec_categories where category_id=:category_id and sort_key=:sort_key select count(*) from ec_categories where category_id=:next_category_id and sort_key=:next_sort_key update ec_categories set sort_key=:next_sort_key where category_id=:category_id update ec_categories set sort_key=:sort_key where category_id=:next_category_id