DISTINCT does not work ?

I have a query and it´s working ok, but i need to get rid of those doubles i get from database.
i thought that DISTINCT would help me this one, but result is same with distinct or without. Is there something wrong my clause:

SELECT DISTINCT Atmtil_0.Tukoodi, Atmtil_0.Atkno, Atmtil_0.Atyks, Atmtil_0.Atnet
FROM PUB.Atmtil Atmtil_0
WHERE (Atmtil_0.Atkno>=200704 And Atmtil_0.Atkno<=200706)

Database is progress running with linux. And i use exel MS query.

T
ToubeAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I don't know postgres enough to be aware of it supporting the query or not...
so I can only assume that it is a case sensitive issue:

SELECT A.Tukoodi
, MIN(A.Atkno) from_Atkno
, MAX(A.Atkno) to_Atkno
, SUM(A.Atyks) Atyks
, SUM(A.Atnet) AtNet
FROM PUB.Atmtil Atmtil_0 A
WHERE (A.Atkno>=200704 And A.Atkno<=200706)
GROUP BY A.Tukoodi
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
DISTINCT returns a DISTINCT on all the returned columns, not only on the first column...

so, what do you define a "double" (or duplicate), please show sample data of what you get, and show the data you would like to get.
0
 
ToubeAuthor Commented:
I need to have 3 months sales count between 200704-200706. Tukoodi is product code and it shoud be shown only one time, now as you can see it gives me same code on every month. like this:

Tukoodi      Atkno      Atyks      Atnet
100018      200704      1      76
100018      200705      1      1
100018      200705      1      98
100018      200706      1      76
100018      200706      2      1
100018      200706      2      195
100019      200704      1      137
100019      200705      1      1
100019      200705      1      252

It should be like this:

Tukoodi      Atkno                          Atyks      Atnet
100018      200704 - 200706             8      447¬
100019      200704 - 200706        3                    390

T



0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
please check out this:

SELECT A.Tukoodi
, MIN(a.Atkno) from_Atkno
, MAX(a.Atkno) from_Atkno
, SUM(a.Atyks) Atyks
, SUM(a.Atnet) AtNet
FROM PUB.Atmtil Atmtil_0 a
WHERE (a.Atkno>=200704 And a.Atkno<=200706)
GROUP BY A.Tukoodi

0
 
ToubeAuthor Commented:
When i run query i get "column not found/specified (7520)"
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I named 2 columns from_Atkno... please try this:

SELECT A.Tukoodi
, MIN(a.Atkno) from_Atkno
, MAX(a.Atkno) to_Atkno
, SUM(a.Atyks) Atyks
, SUM(a.Atnet) AtNet
FROM PUB.Atmtil Atmtil_0 a
WHERE (a.Atkno>=200704 And a.Atkno<=200706)
GROUP BY A.Tukoodi
0
 
ToubeAuthor Commented:
I get same error message: "column not found/specified (7520)"

0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
the error means that either a column is a reserved word, or contains an invalid character (like a dash "-") or simply a wrong name.
please cross-check again that all names as spelled correctly (including uppercase / lowercase), and try to use double quotes (") around all your names...
0
 
ToubeAuthor Commented:
if i run my query:

SELECT DISTINCT Atmtil_0.Tukoodi, Atmtil_0.Atkno, Atmtil_0.Atyks, Atmtil_0.Atnet
FROM PUB.Atmtil Atmtil_0
WHERE (Atmtil_0.Atkno>=200704 And Atmtil_0.Atkno<=200706)

it will work just fine, without or with DISTINCT is the same result. So no wrong with columns or spelling..

I think clause that you recommend is just what i need, but i need to work it also..

Is there something else to check..?

T

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.