dbTalk Databases Forums  

Help Need for a Query

comp.databases.oracle comp.databases.oracle


Discuss Help Need for a Query in the comp.databases.oracle forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Prabu Krishnan
 
Posts: n/a

Default Help Need for a Query - 06-24-2004 , 09:24 AM






Table Name : Emp

EID ENAME
------ ----------
1001 John
1002 Gokul
1003 Daniel
1004 John
1005 Gokul
1006 Daniel


I need the Result as the following By a Single SQL Query


EID ENAME
------ ----------
1001 John
1004 DO
1002 Gokul
1005 DO
1003 Daniel
1006 DO

Reply With Quote
  #2  
Old   
Bent Stigsen
 
Posts: n/a

Default Re: Help Need for a Query - 06-25-2004 , 06:49 AM






Prabu Krishnan wrote:
[snip]
Quote:
I need the Result as the following By a Single SQL Query


EID ENAME
------ ----------
1001 John
1004 DO
1002 Gokul
1005 DO
1003 Daniel
1006 DO
This should get you started, but you should rewrite it so it used outer
joins on subselects of the emp table, because the below sql would be
painfully slow.

select
e.eid,
(select case when min(eid)=e.eid then ename else 'DO' end from emp
where ename=e.ename group by ename) ename
from emp e
order by (select min(eid) from emp where ename=e.ename group by ename),
e.eid


/Bent


Reply With Quote
  #3  
Old   
Ed prochak
 
Posts: n/a

Default Re: Help Need for a Query - 06-25-2004 , 11:29 AM



prabukrishna_msc (AT) yahoo (DOT) com (Prabu Krishnan) wrote in message news:<807a409.0406240624.3534481d (AT) posting (DOT) google.com>...
Quote:
Table Name : Emp

EID ENAME
------ ----------
1001 John
1002 Gokul
1003 Daniel
1004 John
1005 Gokul
1006 Daniel


I need the Result as the following By a Single SQL Query


EID ENAME
------ ----------
1001 John
1004 DO
1002 Gokul
1005 DO
1003 Daniel
1006 DO
What have you tried?
(You don't really expect us to do all of your homework for you, do you?)


Reply With Quote
Reply




Thread Tools
Display Modes

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.