There are three fields in a table:
Field1 Field2 Field3
1 2 3
1 3 4
1 4 5
2 2 3
2 3 4
how can i use distinct to get values 1 2 3 and 2 2 3 only according distinct of field1? Thanks a lot.
Printable View
There are three fields in a table:
Field1 Field2 Field3
1 2 3
1 3 4
1 4 5
2 2 3
2 3 4
how can i use distinct to get values 1 2 3 and 2 2 3 only according distinct of field1? Thanks a lot.
I think you can better use 2 cursors
set serveroutput on
declare
cursor c1 is
select distinct field1 from table
;
cursor c2(p_f1 table.field1%type)
select *
from table
where field1 = p_f1
order by field1,field2,field3
;
rc2 c2%rowtype;
begin
for vc1 in c1
loop
open c2(vc1.field1);
fetch c2 into rc2;
close vc2;
dbms_output.put_line(vc2.field1);
dbms_output.put_line(vc2.field2);
dbms_output.put_line(vc2.field2);
end loop;
end;
/
I can't think of a simple select right now
David,
According to the sample data you have given, the following
query should work
Select Field1, min(Field2), min(Field3) from Table1
Group by Field1
- Nandu
bensr - I know we've talked about this before :), never use PL/SQL when SQL will do, and SQL will almost always do.
- ChrisCode:SELECT
Field1,
Field2,
Field3
FROM
(
SELECT
T.Field1,
T.Field2,
T.Field3,
ROW_NUMBER()
OVER(
PARTITION BY
Field1
ORDER BY
Field2,
Field3
AS RN
FROM
Table T
)
WHERE
RN = 1