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.
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 schemaCREATE 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_itemgroup by order_idMadhivananFailing to plan is Planning to fail |
|
|
Kuriyama
Starting Member
4 Posts |
Posted - 2009-04-27 : 14:16:22
|
This seems to work correctly. Thank you for the assistance. |
|
|
dsindo
Starting Member
45 Posts |
Posted - 2009-04-27 : 17:19:20
|
select distinct order_id, sku from cablestogo_receipt_item |
|
|
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 wantedMadhivananFailing to plan is Planning to fail |
|
|
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 wantedMadhivananFailing 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.... |
|
|
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."MadhivananFailing to plan is Planning to fail |
|
|
|
|
|
|
|