Reputation: 2084
I have a table with 2 columns.
Date_Réserv
e(type of Date), Heure_Réserve
(type of Time)
What I want to do is select the result ordered by the Date_Réserve
and then thie result I get is ordered by Heure_Réserve
.
this is the query I tried :
select * from (select Date_Réserve,Heure_Réserve from réserve order by Date_Réserve)t order by Heure_Réserve
But It gives me this error:
The ORDER BY clause is invalid in views, inline functions, derived tables, and subqueries, unless TOP is also specified.
Upvotes: 3
Views: 8816
Reputation: 4519
List needed columns separated by comma:
select Date_Réserve, Heure_Réserve from réserve
order by Date_Réserve, Heure_Réserve
Upvotes: 5
Reputation: 1750
You can use an order by in a sub query when you use a TOP statement.
select * from
(select TOP 100 PERCENT Date_Réserve,Heure_Réserve from réserve order by Date_Réserve) t order by Heure_Réserve
Upvotes: 0
Reputation: 35716
One clause, two parts
select
Date_Réserve,
Heure_Réserve
from
réserve
order by
Date_Réserve,
Heure_Réserve
--
If this is just an example and you really need to order the results by a column that will be unavailable in the outer query you could do,
select
Date_Réserve,
Heure_Réserve
from
(
select
(ROWNUMBER() OVER ORDER BY Date_Réserve) do,
Date_Réserve,
Heure_Réserve
from
réserve
)
order by
do,
Heure_Réserve
but, as you can see, that would be pointless and inappropriate in your scenario.
Upvotes: 1
Reputation: 16714
If you want to order by more than one column:
select Date_Réserve,Heure_Réserve
from réserve
order by Date_Réserve, Heure_Réserve
If not, the order in subquery is useless.
Upvotes: 2
Reputation: 3397
try this:
SELECT Date_Réserve, Heure_Réserve FROMréserve ORDER BY Date_Réserve ASC, Heure_Réserve ASC
Upvotes: 3
Reputation: 499002
You do not need to use ORDER BY
in your sub query - it is meaningless there.
For primary/secondary sort, you use a single ORDER BY
:
SELECT Date_Réserve,Heure_Réserve
FROM réserve
ORDER BY Date_Réserve, Heure_Réserve
Upvotes: 5