If I understand correctly, S.NO is just the row-number in the results, and added with PHP.
If the query does not sort the result and S.NO has no relation with the data from the database, you cannot sort on this column, and it would not make any sense to do so.
Explanation
SQL queries without an 'ORDER BY xxx' will return the results in a random order; SQL Server UNION - What is the default ORDER BY Behaviour
Basically, this means that every time you run the query, the results may come back in a different order.
The S.NO you're adding is based on the order in which the results came back from your query, but because this order is random, each time you view the same page, the same record may get another position, thus another S.NO
Options
Specify a column to sort the results on so that the order of the results is consistent each time. You'll be able to reverse the sort-order as well if desired. S.NO can still be used, but purely for presentation
Alternatively, calculate the row position using SQL (Get row position in MYSQL query). However, even in this case row number is based on the position of each row in the results. If no ORDER BY
is present, row number is still 'random' and the same row may get a different S.NO / row number each time the query is executed.
The final option is to sort using JavaScript (as others suggested). however, also because of the 'random' order, this can only be done for the records that are visible on the page. If you're using pagination (page x of y), sorting the entire database table will require a new query on the database (which cannot be ordered because of the whole 'random' issue)