Sort databases by category correctly