473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Why ORACLE doesn't do it?

Under the following schema

emp = (empNO, sal)

To get the employee with the largest salary we do:

SELECT empNO, sal
FROM emp
WHERE sal = (SELECT MAX(sal) FROM emp)

Right?

So we calculate the maximum salary first, then we find the employees
that achive that maximum.

Suppose that there is one employee that achieves the maximum.

Why can't ORACLE find the desired empNO directly?

I suppose something like:

SELECT empNO that corresponds to the max, Max(sal)
FROM emp

For sure this is wrong becuase the select list contains only
aggregated or grouped expressions

As far as I know, to get the maximum salary, Oracle scans the rows one
by one, keeping the maximum salary in a "variable" to return it. So
ORACLE knows the record which caused updating the "variable". Why
can't we exploit this to get other values in the row that achieved
that maximum?
Jul 19 '05 #1
2 3651
Actually, since Oracle 8.1.6, this query and other more complicated
ones can be answered by analytic functions.

select *
from emp
where sal = (select max(sal) from emp)

can be written as

select *
from
(select a.*, rank() over (order by sal desc) as rnk
from emp a
)
where rnk = 1

This might appear more convoluted than your traditional approach. But
I find it easier to rewrite when you need to vary the original
business question. Like you can get Top-n and not just Top-1.

af***@mail2world.com (Bilal Sallakh) wrote in message news:<d5**************************@posting.google. com>...
Under the following schema

emp = (empNO, sal)

To get the employee with the largest salary we do:

SELECT empNO, sal
FROM emp
WHERE sal = (SELECT MAX(sal) FROM emp)

Right?

So we calculate the maximum salary first, then we find the employees
that achive that maximum.

Suppose that there is one employee that achieves the maximum.

Why can't ORACLE find the desired empNO directly?

I suppose something like:

SELECT empNO that corresponds to the max, Max(sal)
FROM emp

For sure this is wrong becuase the select list contains only
aggregated or grouped expressions

As far as I know, to get the maximum salary, Oracle scans the rows one
by one, keeping the maximum salary in a "variable" to return it. So
ORACLE knows the record which caused updating the "variable". Why
can't we exploit this to get other values in the row that achieved
that maximum?

Jul 19 '05 #2
Also if sal is indexed then Oracle can use the index to find the max sal.
Jim
"Romeo Olympia" <ro******@hotmail.com> wrote in message
news:42**************************@posting.google.c om...
Actually, since Oracle 8.1.6, this query and other more complicated
ones can be answered by analytic functions.

select *
from emp
where sal = (select max(sal) from emp)

can be written as

select *
from
(select a.*, rank() over (order by sal desc) as rnk
from emp a
)
where rnk = 1

This might appear more convoluted than your traditional approach. But
I find it easier to rewrite when you need to vary the original
business question. Like you can get Top-n and not just Top-1.

af***@mail2world.com (Bilal Sallakh) wrote in message

news:<d5**************************@posting.google. com>...
Under the following schema

emp = (empNO, sal)

To get the employee with the largest salary we do:

SELECT empNO, sal
FROM emp
WHERE sal = (SELECT MAX(sal) FROM emp)

Right?

So we calculate the maximum salary first, then we find the employees
that achive that maximum.

Suppose that there is one employee that achieves the maximum.

Why can't ORACLE find the desired empNO directly?

I suppose something like:

SELECT empNO that corresponds to the max, Max(sal)
FROM emp

For sure this is wrong becuase the select list contains only
aggregated or grouped expressions

As far as I know, to get the maximum salary, Oracle scans the rows one
by one, keeping the maximum salary in a "variable" to return it. So
ORACLE knows the record which caused updating the "variable". Why
can't we exploit this to get other values in the row that achieved
that maximum?

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gustavo Oliveira | last post by:
Hi, I'm desperate... I've been installed Oracle Client. 9.1i in some computers and 9.2i in others. The installation was sucefull, because, I can use SQL Plus, without problems... Now...
7
by: Domenic G. | last post by:
I was wondering how many Oracle DBAs out there have bosses that are complete doe-doe birds? My current boss is a beaut -- has absolutely no concept of Oracle, keeps flipping back and forth from...
5
by: michael newport | last post by:
Oracle opens arms to Mozilla By Stephen Shankland and Alorie Gilbert, CNET News.com Oracle wants its applications to integrate better with Mozilla's open-source desktop software Oracle is...
125
by: Rhino | last post by:
One of my friends, Scott, is a consultant who doesn't currently have newsgroup access so I am asking these questions for him. I'll be telling him how to monitor the answers via Google Newsgroup...
28
by: prunoki | last post by:
Hello, I am an SQL server newbie. Our company has a massive application written in PL/SQL. I need to port parts of it to SQL Server. - Which SQL server version should I choose, to have a...
13
by: BigDaDDY | last post by:
Um yeah....In case you haven't figured it out, Microsoft sucks. I'm going to be kicked back in my chair eating popcorn and watching football 10 years from now, while all you clowns are scrambling...
14
by: tristant | last post by:
Hi All, Our client has just decided to migrate from SQLServer2k to Oracle 9i on AIX. We are considering what development tool / language as the application/ front end platform. We almost...
5
by: Michael Rudolph | last post by:
Hi newsgroup, I have an issue with the configuration of a DB2 federated database (WebSphere Information Integrator) in conjunction with the relational wrapper for Oracle on AIX. DB2 seems to not...
56
by: Ashish Patankar | last post by:
I want to migrate my Oracle 10g database to Db2. I want some documentation for the comparision between these to databases. I also want to know which features of Oracle 10g are supported by Db2 and...
1
by: shaguna.dhall | last post by:
I need to migrate Unicode data from MS Access to Oracle. Have tried the following: -Exported the Access tables to csv/txt, but these files were generated in ANSI encoding, and the Unicode data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.