Reputation: 1376
I have a table with data like
I want all the records from the table but which the record having EnquiryStatus=1 and order by LastAttendendedDate should come on the top and remaining records should come after those records. I tried to select twice with where condition and tried to union all them, But with that union all not allowing me to order by on different ways. I can do it in c# by retriving the data as two table and merge them as single. But I want it in sql..
EDITS:
I want something like
Select * From EnquiryMaster A Where A.BranchID=16 and EnquiryStatus=1 ORDER BY A.CreatedDate Desc
UNION ALL
Select * From EnquiryMaster A Where A.BranchID=16 and EnquiryStatus in(0,2,3) ORDER BY EnquiryStatus,A.CreatedDate Desc
Upvotes: 0
Views: 113
Reputation: 3289
SELECT * FROM TABLE_NAME WHERE ORDER BY CASE WHEN EnquiryStatus='1' THEN LastAttendendedDate END DESC
You can use this in sql.
Upvotes: 2
Reputation: 13700
Try this
select * from your_table
order by case when EnquiryStatus=1 then LastAttendendedDate end DESC
Upvotes: 1