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)
 Problem with SELECT DISTINCT

Author  Topic 

befree
Starting Member

3 Posts

Posted - 2001-02-06 : 20:39:36
Hi,

An query like the following one :

SELECT DISTINCT column_name1, column_name2, column_name3 FROM table

eliminates duplicate rows based on the =3= columns.

What I want is to create a query which returns all the records that are duplicate on =only one= column.

Ex : a query with no duplicate based only on userid on this table :

Userid Session Dt_connect
------ --------- -----------------------
20107 578631748 2001-02-04 15:18:16.000
20107 578631748 2001-02-04 15:19:50.000
20107 578624023 2001-02-01 21:02:50.000
20107 578624023 2001-02-01 21:03:21.000
29605 578626716 2001-02-02 19:55:11.000
29605 578626716 2001-02-02 19:55:27.000

the query should give this result :

Userid Session Dt_connect
------ --------- -----------------------
20107 578631748 2001-02-04 15:18:16.000
20107 578624023 2001-02-01 21:02:50.000
29605 578626716 2001-02-02 19:55:11.000

In some SQL versions, you can use "DISTINCT ON" but I don't think MS SQL 2000 support this.

How can I solve this problem ?


-= BeFree =-
   

- Advertisement -