Reputation: 11
SELECT * FROM TT
ORDER BY (SELECT AGE
FROM TTT
WHERE NAME='TANDEL'
);
Result is,
JOHN 2
PRAVEEN 2
KUMAR 2
RAKESH 2
WASIB 2
GURUNG 2
DAYALAN 5
DEEPAK 2
TANDEL 5
RAGHU 5
GIGA 5
DEEPA 5
DEVARAJ 2
Note: Table TT and TTT both have same data.
Upvotes: 0
Views: 57
Reputation: 1033
In the order by clause we can add two thing:
Column names
Select * from TTT order by age;
Coulmn number to filter
Select * from TTT order by 2;//if age is the second column in the table
or
Select name,age from TTT order by 2; // this will order by age
In the following case the inner query
SELECT AGE
FROM TTT
WHERE NAME='TANDEL'
will return 5
and the parent query
SELECT * FROM TT
ORDER BY 5
Upvotes: 0
Reputation: 13484
Order By requires a column or some columns
SELECT *
FROM TT
ORDER BY colname
Upvotes: 1
Reputation: 93
Quite simply, it's not working. Order By requires a column or columns, if random data is passed into it instead of column names, it does nothing.
Upvotes: 4