question

newbie2 avatar image
newbie2 asked

How can I order this?

Select distinct s from Student s left join fetch s.accounts where s.id=:studId The code above is valid....it shows all the accounts of the student with the correct id (studId) Now, all the accounts are shown, but they are not sorted... All of them have the property ID (integer) I want to sort them, but i have no idea how to access them... I tried this already: Select distinct s from Student s left join fetch s.accounts where s.id=:studId ORDER BY _____ s.accounts.id accounts.id account.id s.account.id but it does not work....can u help me?
sqlorder-bydistinct
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

GPO avatar image GPO commented ·
"...The code above is valid..." In which SQL dialect?
1 Like 1 ·

1 Answer

·
virendrasingh_77 avatar image
virendrasingh_77 answered
When you use the ORDER BY clause with DISTINCT, you have to select all items that appear in the ORDER BY clause.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.