I am asked a question in interview that sort result without using of order by clause and without using the script like php. I enough google it but did not find the way. Is there any method to sort results in this way. And it should be without using of any script like php etc.
You cannot, at least not reliably.
Some SQL implementations may well return rows in the order of their primary keys or clustered indexes, but SQL itself is a relational algebra that returns arbitrarily ordered sets unless specifically told otherwise.
There's a good chance that the order in which rows are returned may well depend on the insertion and deletion activity since the table was created.
My answer to an interview question like that would be:
Is there some sort of reason why we can't use 'order by' in our queries? Is the company so hard up for money that they cannot afford the disk space to store those extra few bytes for each query? Are you out of you goddamned mind? Ask me a question that's going to have some relevance :-)
I expect they were fishing to see if you knew that most SQL implementations in general do not guarantee the order of rows returned unless you explicitly use an order by clause.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With