?
Solved

DISTINCT does not work ?

Posted on 2007-08-02
9
Medium Priority
?
365 Views
Last Modified: 2012-08-14
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
0
Comment
Question by:Toube
  • 5
  • 4
9 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 19615124
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
 

Author Comment

by:Toube
ID: 19615269
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 19615338
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Toube
ID: 19616942
When i run query i get "column not found/specified (7520)"
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 19616958
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
 

Author Comment

by:Toube
ID: 19618536
I get same error message: "column not found/specified (7520)"

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 19618611
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
 

Author Comment

by:Toube
ID: 19619701
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
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 19620665
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Integration Management Part 2
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question