| Get a specific record in duplicates [message #563785] |
Fri, 17 August 2012 02:08  |
 |
Gurusank
Messages: 8 Registered: September 2011
|
Junior Member |
|
|
Hi Experts,
I have a requirement with source table has duplicates so i need to select a row based upon the below condition.
Source table
EMP_NO ENAME SALARY CODE EMP_ID
1 TOM 1000 1 10
1 JOHN 2000 A 20
1 SAM 3000 A 30
2 TOM 500 1 40
2 SUNG 1500 1 50
Desired Output
EMP_NO ENAME SALARY CODE EMP_ID
1 TOM 1000 1 10
2 SUNG 1500 1 50
I tried with MAX and DENSE_RANK but its not getting me the first row.
Please help.
Thanks,
Gurusank
|
|
|
|
|
|
|
|
|
|
| Re: Get a specific record in duplicates [message #563810 is a reply to message #563785] |
Fri, 17 August 2012 05:32   |
Solomon Yakobson
Messages: 1397 Registered: January 2010
|
Senior Member |
|
|
with sample_table as (
select 1 emp_no,'TOM' ename,1000 salary,'1' code,10 emp_id from dual union all
select 1,'JOHN',2000,'A',20 from dual union all
select 1,'SAM',3000,'A',30 from dual union all
select 2,'TOM',500,'1',40 from dual union all
select 2,'SUNG',1500,'1',50 from dual
)
select emp_no,
ename,
salary,
code,
emp_id
from (
select s.*,
row_number() over(order by emp_id) rn_first,
row_number() over(order by emp_id desc) rn_last
from sample_table s
)
where rn_first = 1
or rn_last = 1
order by emp_id
/
EMP_NO ENAM SALARY C EMP_ID
---------- ---- ---------- - ----------
1 TOM 1000 1 10
2 SUNG 1500 1 50
SQL>
SY.
|
|
|
|
|
|
|
|
|
|
| Re: Get a specific record in duplicates [message #563868 is a reply to message #563865] |
Fri, 17 August 2012 11:17  |
 |
Michel Cadot
Messages: 54126 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Gurusank wrote on Fri, 17 August 2012 17:51Michel,
Instead of bluffing and asking pointless questions why dont u really "try" to help those who need help. If not please dont intrude from those who is giving help.
Moreover, i am not here just to get spoonfeeded rather to get some ideas from the problems i encounter. For my every post u are the first to give me reply on mistakes rather than any pea nut of help.
BTW, Glad i solved the problem by myself without of your spoonfeeding.
Thanks,
Gurusank
You did not define what is a duplicate.
I have another answer to your question:
EMP_NO ENAM SALARY C EMP_ID
---------- ---- ---------- - ----------
1 TOM 1000 1 10
2 SUNG 1500 1 50
Tell us why
2 TOM 500 1 40
is not in the result?
It has CODE=1 as you asked.
Is it a pointless question?
Trying to help is not providing a query that gives the same result that you ask.
I think it is much better helping to help people learn how to specify their problem and question. But of course, this is for smart and not lazy people, it seems you are not so I don't care to not help you.
At least, next time, follow the guide, if you are able to do it.
Regards
Michel
|
|
|
|