SQL Language (MOSC)

MOSC Banner

Need Assist With DISTINCT Query

edited Jul 13, 2011 2:43AM in SQL Language (MOSC) 11 commentsAnswered ✓
 Hi Folks

going to try this again

I am trying to eliminate duplicate dataids

****

This what is there

*****

select to_char (auditdate,'yyyy') year_sel, dataid from dauditnew where dataid in
(
37035736,
37035538,
37034739,
37034740,
37034741,
37034742,
37034743,
37034744,
37034745,
37034746
);


YEAR     DataID
---- ----------
2005   37034739
2005   37034739
2005   37034740
2005   37034740
2005   37034741
2005   37034741
2005   37034742
2005   37034742
2005   37034743
2005   37034743
2005   37034744
2005   37034744
2005   37034745
2005   37034745
2005   37034746
2005   37034746
2005   37035538
2005   37035538
2005   37035736
2005   37035736

20 rows selected.

****

Count to verify

*****

select to_char (auditdate,'yyyy') year_sel, dataid, COUNT (dataid)from dauditnew where dataid in
(
37035736,
37035538,
37034739,
37034740,
37034741,
37034742,
37034743,
37034744,
37034745,
37034746
)
group by
to_char (auditdate,'yyyy'), dataid
order by
to_char (auditdate,'yyyy'), dataid;

YEAR     DataID COUNT(DATAID)
---- ---------- -------------
2005   37034739             2
2005   37034740             2
2005   37034741             2
2005   37034742             2
2005   37034743             2
2005   37034744             2
2005   37034745             2
2005   37034746             2
2005   37035538             2
2005   37035736             2

****

try to elimiate duplicates

*****

select
to_char (auditdate,'yyyy') year_sel,
distinct (dataid) dataid
from dauditnew where dataid in
(
37035736,
37035538,
37034739,
37034740,
37034741,
37034742,
37034743,
37034744,
37034745,
37034746
)
group by
to_char (auditdate,'yyyy'), dataid

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center