Home » SQL & PL/SQL » SQL & PL/SQL » TYPICAL QUERY..Experts ??
TYPICAL QUERY..Experts ?? [message #227287] Tue, 27 March 2007 20:58 Go to next message
parlovi
Messages: 6
Registered: February 2007
Location: BANGALORE
Junior Member
Hi All,

Recently I came across a stuff to write query for below scenario.
There are two tables and their structure is as below.

Create table EMP (eno ,ename ,sal) - 2rows
Create table GRAD ( grads, Low ,High ) - 3 rows
values for EMP              values for GRAD

ENO  ENAME  SAL             GRAD   LOW  HIGH
 1    X     1000              1    1000  5000
 2    Y    10000              2    5001  7500
                              3    7501 10000


So as u can see here GRAD table contains grad of employee for different salary range.

I have to write a query which gives in output ENAME,SAL & GRAD for that employee i.e in which grad his/her salary lies.

I tried to do it in joins and correlated sub query but I was not able to do it better.

Can someone plz Help here ?
Thanks for your efforts.

Regards,
P

[Updated on: Tue, 27 March 2007 21:00]

Report message to a moderator

Re: TYPICAL QUERY..Experts ?? [message #227290 is a reply to message #227287] Tue, 27 March 2007 21:23 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>I tried to do it in joins and correlated sub query but I was not able to do it better.
Better than what?
What did you try & why was it lacking?
Why is this an EXPERT question to only join two tables?
Have you EVER written your own SQL that joined two tables?
Re: TYPICAL QUERY..Experts ?? [message #227386 is a reply to message #227290] Wed, 28 March 2007 02:20 Go to previous messageGo to next message
muzahid
Messages: 281
Registered: September 2004
Location: Dhaka, Bangladesh
Senior Member
select a.ENO, a.ENAME, a.SAL, b.GRAD
from emp a, grad b
where
a.SAL between b.LOW and b.HIGH
Re: TYPICAL QUERY..Experts ?? [message #227417 is a reply to message #227287] Wed, 28 March 2007 03:40 Go to previous message
Tanveer_ht
Messages: 7
Registered: March 2007
Junior Member
SELECT ename,sal,grads
FROM employee e,grade g
WHERE e.sal BETWEEN (g.low) AND (g.high)
Previous Topic: how to use between
Next Topic: Tuning of the Procedure
Goto Forum:
  


Current Time: Sat Dec 07 04:46:45 CST 2024