x

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?

more ▼

asked Nov 15, 2016 at 04:40 PM in Default

avatar image

newbie2
1 1

"...The code above is valid..." In which SQL dialect?

Nov 17, 2016 at 10:27 AM GPO
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

When you use the ORDER BY clause with DISTINCT, you have to select all items that appear in the ORDER BY clause.

more ▼

answered Nov 16, 2016 at 08:16 AM

avatar image

virendrasingh_77
11 2

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x1149
x28
x22

asked: Nov 15, 2016 at 04:40 PM

Seen: 57 times

Last Updated: Nov 17, 2016 at 10:29 AM

Copyright 2017 Redgate Software. Privacy Policy