Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old July 8th, 2004, 04:07 AM
vinoddobhal vinoddobhal is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 vinoddobhal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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?

Reply With Quote
  #2  
Old July 8th, 2004, 07:29 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
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,

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Ordering a result set with a column not in result set or queried tables


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway