Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 16th, 2004, 01:41 AM
Registered User
 
Join Date: Jun 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madkaikar_ashish Send a message via Yahoo to madkaikar_ashish
Default Select distinct data from one column

I have a table 'wRelated' with the following columns

    [related_id] [int]
    [channel_id] [int]
    [mui] [varchar]
    [price_group_id]
    [type_id] [int]
    [related_mui] [varchar] (100)
    [date_started] [smalldatetime]
    [date_ended] [smalldatetime]
    [date_entered] [datetime]
    [deleted] [tinyint],
    [rank] [int]
data in column [mui] is repeated as the table has more than one entries for the same [mui],
The requirement is to select the distinct[mui] but value in all the other columns for the same mui should be select in the next row with null for the same [mui]
The recordset expected should be something like this.

[mui],[related_mui],[price_group_id],[date_entered],[date_ended] m123,rm345,'pr','12-10-2003',12-12-2004'
null,rm789,'ar','12-1-2003',26-2-2004'
null,rm999,'xy','14-12-2002',12-2-2004'
m777,rm889,'pr','12-12-2004',12-12-2004'
null,rm785,'yy','1-10-2002',12-12-2004'
m888,rm345,'pr','2-8-2003',12-12-2004'
null,rm345,'tt','30-7-2002',12-12-2004'

I have tried Unions and temporary table inserts.

ashish
 
Old December 17th, 2004, 10:25 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

Try using distinct

Here a is sample
Code:
SELECT DISTINCT related_id,channel_id,mui,price_group_id,type_id,related_mui,date_started,date_ended,date_entered,deleted,rank 
FROM wRealted
GROUP BY related_id,channel_id,mui,price_group_id,type_id,related_mui,date_started,date_ended,date_entered,deleted,rank


Jaime E. Maccou





Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Distinct kirkmc Access 13 July 13th, 2006 01:26 PM
Select Distinct kirkmc Excel VBA 3 May 5th, 2006 07:55 PM
Distinct SELECT DISTINCT question... EndEffect Classic ASP Databases 4 August 18th, 2005 08:53 AM
Distinct Column Occurrences jemacc SQL Server 2000 2 October 25th, 2004 04:20 AM
select distinct bmains ADO.NET 0 April 8th, 2004 02:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.