Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Record duplication

Author  Topic 

dionismatos
Starting Member

6 Posts

Posted - 2012-02-09 : 14:13:52
Hello all

I'm having issues with a select query that is supposed to return unique rows, instead i'm getting the collection of data i want repeated many times.

what could i be missing? i'm sorry if this is too basic :/

this is my query, Thanks in advance!



SELECT m.moCodigo as 'No. Conduce', m.moFechaCreacion as 'Fecha', m.moTipoMov as 'Movimiento',
m.moDoc as 'Doc. Transporte', u.uDescripcion as 'Origen', c.ceDescripcion as 'Destino',
m.moCantPaletaL as 'Locales',m.moCantPaletaI as 'Importadas', m.moCantPaletaP as 'Paleta Cte.',
(m.moCantPaletaL + m.moCantPaletaI + m.moCantPaletaP) as 'Total Paletas'
FROM movimientos m,
Ubicaciones u,
Clientes c
where moTipoMov = 'salida'
ORDER BY m.moCodigo




visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-09 : 14:15:59
can you post some data and explain what you mean by duplicates and also how expected output should be

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dionismatos
Starting Member

6 Posts

Posted - 2012-02-09 : 14:30:34
I mean by duplicates that my query should display say 46 rows.. instead i get those 46 rows 5 times more...
i'm sorry i cannot post my results: Data is confidential.
but here is an example, the query should return:

Green
Blue
Red

instead i get:

Green
Blue
Red

Green
Blue
Red

Green
Blue
Red

Green
Blue
Red

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-09 : 17:44:54
based on your limited explanation, we can suggest only this


SELECT DISTINCT m.moCodigo as 'No. Conduce', m.moFechaCreacion as 'Fecha', m.moTipoMov as 'Movimiento',
m.moDoc as 'Doc. Transporte', u.uDescripcion as 'Origen', c.ceDescripcion as 'Destino',
m.moCantPaletaL as 'Locales',m.moCantPaletaI as 'Importadas', m.moCantPaletaP as 'Paleta Cte.',
(m.moCantPaletaL + m.moCantPaletaI + m.moCantPaletaP) as 'Total Paletas'
FROM movimientos m,
Ubicaciones u,
Clientes c
where moTipoMov = 'salida'
ORDER BY m.moCodigo

If this is still not what you want then unless we see the data or atleast a good sample representation of it we cant help much as I suspect problem might be with the way tables are actually related

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -