|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Ordering a result set with a column not in result set or queried tables
Sometimes, we need to order a resultset where in we are displaying employee records with a column not in that result set and not even in the table
How can i do that? |
|
#2
|
|||
|
|||
|
You can use such a column in ORDER BY clause that is not in the SELECT clause as long as you have column in the table. Also you can sorting the result set on any expression that is in SELECT clause. you can also concatenate two or more column and use it in order by clause. you can also use column position in ORDER BY clause.
Order by a column that is not appear in SELECT clause: ----------------------------------------------------- SELECT empno, ename, sal, deptno FROM emp ORDER BY hiredate; Order by Expression: ------------------- SELECT empno, ename, sal,deptno,'2' sortby FROM emp UNION SELECT empno, ename, sal,deptno,'1' sortby FROM emp ORDER BY sortby; Order by concatenated columns: -------------------------------- SELECT first_name||' '||Last_name name, salary, deptno FROM emp_details order by name; Order by column position: ------------------------ SELECT empno, ename, sal, deptno FROM emp ORDER BY 1,2; Regards, |
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > Ordering a result set with a column not in result set or queried tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|