Solved

why DISTINCT it is not working

Posted on 2014-10-20
4
164 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
  • 3
4 Comments
 
LVL 73

Expert Comment

by:sdstuber
Comment Utility
you probably have white space in the columns you can't see
0
 
LVL 73

Assisted Solution

by:sdstuber
sdstuber earned 500 total points
Comment Utility
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
Comment Utility
i agree

1      11      Mantenimiento Palmas      20
2      11      Mantenimiento Palmas       21

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

Accepted Solution

by:
sdstuber earned 500 total points
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to recover a database from a user managed backup

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now