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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 SQL Query : Removing duplicate data

Author  Topic 

Kuriyama
Starting Member

4 Posts

Posted - 2009-04-27 : 10:02:56
I'm attempting to generate a list of order receipts. The catch is that I need to remove duplicated sku numbers per order from the list. What this means is that in the table below if a sku exists twice in one order, I only want to return that sku once.

Order Table schema


CREATE TABLE [dbo].[cablestogo_receipt_item] (
[order_id] [char] (26),
[sku] [varchar] (255),
[quantity] [int] NULL ,
[price] [float] NULL ,
)

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-27 : 10:24:20
Is this?

Select order_id,min(sku) as sku from cablestogo_receipt_item
group by order_id

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kuriyama
Starting Member

4 Posts

Posted - 2009-04-27 : 14:16:22
This seems to work correctly. Thank you for the assistance.
Go to Top of Page

dsindo
Starting Member

45 Posts

Posted - 2009-04-27 : 17:19:20
select distinct order_id, sku from cablestogo_receipt_item
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-28 : 02:29:33
quote:
Originally posted by dsindo

select distinct order_id, sku from cablestogo_receipt_item


There is no necessary that it should work the way OP wanted

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2009-04-29 : 01:18:24
quote:
Originally posted by madhivanan

quote:
Originally posted by dsindo

select distinct order_id, sku from cablestogo_receipt_item


There is no necessary that it should work the way OP wanted

Madhivanan

Failing to plan is Planning to fail


Madhivanan,
Just for curiousity, could u explain why dsindo's query will not work always?
bcos, distinct will always fetch distict records based on the those 2 fields..

thanx in advance....
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-29 : 02:35:41
Becuase OP said "The catch is that I need to remove duplicated sku numbers per order from the list."

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -