Solved

why DISTINCT it is not working

Posted on 2014-10-20
4
186 Views
Last Modified: 2014-10-20
Por que no funciona el distinct
SELECT DISTINCT G.IDGERENCIA, GS.AREA
  FROM TA_GASTOS_STAGE GS
       INNER JOIN TA_GERENCIA G ON GS.GERENCIA_DIRECCIÓN = G.NOMBREGERENCIA
WHERE
       GS.AREA LIKE '%Mantenimiento Palmas%'  
ORDER BY G.IDGERENCIA,GS.AREA

         IDGERENCIA      AREA
1      11      Mantenimiento Palmas
2      11      Mantenimiento Palmas

this is the table_stage
SELECT *
  FROM TA_GASTOS_STAGE GS
WHERE
       GS.AREA LIKE '%Mantenimiento Palmas%'  
         TIPO      CECO      DESCRIPCION_CECO      F4      GERENCIA_DIRECCIÓN      AREA      PLANTA      RESPONSABLE      F9      F10      F11      F12      F13      F14      F15      F16
1      Producción      10P30803      Soplado Palmas Supervisión Mantenimiento            Gerencia Producción Soplado      Mantenimiento Palmas       Palmas                                                      
2      Producción      10P30804      Soplado Palmas  Mantenimiento            Gerencia Producción Soplado      Mantenimiento Palmas      Palmas
0
Comment
Question by:enrique_aeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 40392676
you probably have white space in the columns you can't see
0
 
LVL 74

Assisted Solution

by:sdstuber
sdstuber earned 500 total points
ID: 40392677
try this to see if you have extra invisible white space


SELECT DISTINCT G.IDGERENCIA, GS.AREA, length(gs.area)
  FROM TA_GASTOS_STAGE GS
       INNER JOIN TA_GERENCIA G ON GS.GERENCIA_DIRECCIÓN = G.NOMBREGERENCIA
WHERE
       GS.AREA LIKE '%Mantenimiento Palmas%'  
ORDER BY G.IDGERENCIA,GS.AREA
0
 

Author Comment

by:enrique_aeo
ID: 40392687
i agree

1      11      Mantenimiento Palmas      20
2      11      Mantenimiento Palmas       21

As I can do an UPDATE to remove blanks?
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 40392689
try this...


update  TA_GASTOS_STAGE set area = trim(area)

or, to only remove trailing blanks

update  TA_GASTOS_STAGE set area = rtrim(area)
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
T-SQL Query - Group By Year 3 55
Creating a View from a CTE 15 49
Queries: Select, then Append, then Delete 8 41
supress error message in oracle form 4 15
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

752 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