Sorting Order by

Hi,

I have a select statement where i need to sort the order by statement. I read that you lose data when sorting on a group by. Is this possible on one table?

select firstonly salesId from Salesline

group by salesid

order by entApprovedForInvoicing desc

where Salesline.SalesStatus == SalesStatus::BackOrder

let me know your thoughts on this. Thanks!

Schneizer

The query doesn’t make much sense to me. How do you want to sort by a field that that disappears by your grouping? Or if you mean sorting before grouping, it doesn’t actually matter - the group will always look the same regardless of the order of records inside the group

Anyway, the answer is that order by will be ignored (even in cases where it would make sense) if you use group by at the same time.

(Question moved from the End User forum.)

Thank you for your reply Martin!

But anyhow, are there any methods of sorting a group by? The one stated on my post was just an example.

I believe I already gave you the general answer.

You can use some workarounds, but what to do depends on what you’re trying to achieve. If your previous examples doesn’t show your actual problem, can you give us a better example?