Table temp
ID Status
1 completed
2 approved
3 paid
4 cancel
5 approved
6 paid
I want to display above recored as per bellow table without using union.because this is client requirement, so please provide help for this.
Table temp
ID Status
1 completed
2 approved
5 approved
3 paid
6 paid
4 cancel
Almost identical to Dan’s answer, but for SQL Server (Or any standards SQL database system):
Other concerns –
1) The title of this question appears to be misleading, since it’s not about GROUP BY at all, and,
2) I think you have a misconception about
UNIONalso – there’s no guarantee of the order in which results will return from aUNIONorUNION ALL– In theUNIONcase, there’s likely to be a sort operation to help the server to eliminate duplicates, but which sort is performed is entirely up to the server and you shouldn’t rely on such a sort always being necessary. For aUNION ALL, imagine if the first query is a large query, requiring a lot of I/O, and the second query is trivial (say, all of the data required is already in memory). An obvious optimization for the server is to return the results for the second query whilst it’s still performing I/O for the first.