Restricting And Sorting Data In Sql