![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
HI all, I'm trying to use the collect() function (mentioned in my earlier post in this ng) but it, well, collects all values. Is there any way of avoiding duplicates? What I'm trying to do is this: select collect(a1), a2, a3, a4 from A group by a2, a3, a4. Thanks, Sashi |
#3
| |||
| |||
|
|
On Sep 15, 9:47*pm, Sashi <small... (AT) gmail (DOT) com> wrote: HI all, I'm trying to use the collect() function (mentioned in my earlier post in this ng) but it, well, collects all values. Is there any way of avoiding duplicates? What I'm trying to do is this: select collect(a1), a2, a3, a4 from A group by a2, a3, a4. Thanks, Sashi Provide some sample data so we can test this ourselves. David Fitzjarrell |
#4
| |||
| |||
|
|
On Sep 16, 7:49*am, ddf <orat... (AT) msn (DOT) com> wrote: On Sep 15, 9:47*pm, Sashi <small... (AT) gmail (DOT) com> wrote: HI all, I'm trying to use the collect() function (mentioned in my earlier post in this ng) but it, well, collects all values. Is there any way of avoiding duplicates? What I'm trying to do is this: select collect(a1), a2, a3, a4 from A group by a2, a3, a4. Thanks, Sashi Provide some sample data so we can test this ourselves. David Fitzjarrell DDL: create table employee(dept_id varchar(4), fname varchar(20), lname varchar(20)); DML: insert into employee(dept_id, fname, lname) values ('1', 'John', 'Smith'); insert into employee(dept_id, fname, lname) values ('1', 'Jane', 'Smith'); insert into employee(dept_id, fname, lname) values ('1', 'Harry', 'Arnold'); insert into employee(dept_id, fname, lname) values ('2', 'Sam', 'Smith'); insert into employee(dept_id, fname, lname) values ('2', 'Samantha', 'Smith'); insert into employee(dept_id, fname, lname) values ('2', 'Peter', 'Jones'); Fetch: select dept_id, collect(lname) from employee group by dept_id Result: DEPT, COLLECT(LNAME) ---------------------------------------------------------------------------*----- 1, SYSTPc7POHe3EMMDgRAAAvqlgUw==('Smith', 'Smith', 'Arnold') 2, SYSTPc7POHe3EMMDgRAAAvqlgUw==('Smith', 'Smith', 'Jones') The collect function 'collects' requested values and returns it as a collection. It, however, does store dups. I'd like to avoid the dups. Googling around didn't help much (or I did a bad job of it). Does anyone know how to restrict the collection to distinct values? collect(distinct lname) doesn't help. TIA, Sashi- Hide quoted text - - Show quoted text - |
#5
| |||
| |||
|
|
HI all, I'm trying to use the collect() function (mentioned in my earlier post in this ng) but it, well, collects all values. Is there any way of avoiding duplicates? What I'm trying to do is this: select collect(a1), a2, a3, a4 from A group by a2, a3, a4. Thanks, Sashi |
#6
| |||
| |||
|
|
HI all, I'm trying to use the collect() function (mentioned in my earlier post in this ng) but it, well, collects all values. Is there any way of avoiding duplicates? What I'm trying to do is this: select collect(a1), a2, a3, a4 from A group by a2, a3, a4. |
#7
| |||
| |||
|
|
Sashi <smalladi (AT) gmail (DOT) com> wrote: HI all, I'm trying to use the collect() function (mentioned in my earlier post in this ng) but it, well, collects all values. Is there any way of avoiding duplicates? What I'm trying to do is this: select collect(a1), a2, a3, a4 from A group by a2, a3, a4. select collect(distinct a1)... should work. -- __________________________________________________ _____________________ Dan Blum tool (AT) panix (DOT) com "I wouldn't have believed it myself if I hadn't just made it up." |
#8
| |||
| |||
|
|
"Dan Blum" <t... (AT) panix (DOT) com> a écrit dans le message de news: h8rdtj$e6.... (AT) reader1 (DOT) panix.com...| Sashi <small... (AT) gmail (DOT) com> wrote: | > HI all, I'm trying to use the collect() function (mentioned in my | > earlier post in this ng) but it, well, collects all values. Is there | > any way of avoiding duplicates? | > What I'm trying to do is this: | | > select collect(a1), a2, a3, a4 | > from A | > group by a2, a3, a4. | | select collect(distinct a1)... should work. | | -- | __________________________________________________ _____________________ | Dan Blum * * * * *t... (AT) panix (DOT) com | "I wouldn't have believed it myself if I hadn't just made it up." It does. SQL> select collect(val) from t; COLLECT(VAL) --------------------------------------------- SYSTPYmvHKMavRw27KIB3yptjFg==(1, 2, 1, 1) 1 row selected. SQL> select collect(distinct val) from t; COLLECT(DISTINCTVAL) --------------------------------------------- SYSTPYmvHKMavRw27KIB3yptjFg==(1, 2) 1 row selected. Regards Michel |
#9
| |||
| |||
|
|
On Sep 16, 2:36?pm, "Michel Cadot" <micadot{at}altern{dot}org> wrote: "Dan Blum" <t... (AT) panix (DOT) com> a ?crit dans le message de news: h8rdtj$e6... (AT) reader1 (DOT) panix.com...| Sashi <small... (AT) gmail (DOT) com> wrote: | > HI all, I'm trying to use the collect() function (mentioned in my | > earlier post in this ng) but it, well, collects all values. Is there | > any way of avoiding duplicates? | > What I'm trying to do is this: | | > select collect(a1), a2, a3, a4 | > from A | > group by a2, a3, a4. | | select collect(distinct a1)... should work. | | -- | __________________________________________________ _____________________ | Dan Blum ? ? ? ? ?t... (AT) panix (DOT) com | "I wouldn't have believed it myself if I hadn't just made it up." It does. SQL> select collect(val) from t; COLLECT(VAL) --------------------------------------------- SYSTPYmvHKMavRw27KIB3yptjFg==(1, 2, 1, 1) 1 row selected. SQL> select collect(distinct val) from t; COLLECT(DISTINCTVAL) --------------------------------------------- SYSTPYmvHKMavRw27KIB3yptjFg==(1, 2) 1 row selected. Regards Michel But not with a GROUP BY query: |
#10
| |||
| |||
|
|
On Sep 16, 2:36 pm, "Michel Cadot" <micadot{at}altern{dot}org> wrote: "Dan Blum" <t... (AT) panix (DOT) com> a écrit dans le message de news: h8rdtj$e6... (AT) reader1 (DOT) panix.com...| Sashi <small... (AT) gmail (DOT) com> wrote: | > HI all, I'm trying to use the collect() function (mentioned in my | > earlier post in this ng) but it, well, collects all values. Is there | > any way of avoiding duplicates? | > What I'm trying to do is this: | | > select collect(a1), a2, a3, a4 | > from A | > group by a2, a3, a4. | | select collect(distinct a1)... should work. | | -- | __________________________________________________ _____________________ | Dan Blum t... (AT) panix (DOT) com | "I wouldn't have believed it myself if I hadn't just made it up." It does. SQL> select collect(val) from t; COLLECT(VAL) --------------------------------------------- SYSTPYmvHKMavRw27KIB3yptjFg==(1, 2, 1, 1) 1 row selected. SQL> select collect(distinct val) from t; COLLECT(DISTINCTVAL) --------------------------------------------- SYSTPYmvHKMavRw27KIB3yptjFg==(1, 2) 1 row selected. Regards Michel But not with a GROUP BY query: |
![]() |
| Thread Tools | |
| Display Modes | |
| |