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
 SQL query in SQL Server 2000

Author  Topic 

kartikkumar84
Starting Member

7 Posts

Posted - 2009-07-15 : 06:45:37
Hi

I am relatively new to SQL and databases. I wanted some information from a database at work.

I have result set (after running and sorting a query) with more than 40000 rows.. I am pasting a prtion of it.

A B

10000050 2
10000050 7
10000051 7
10000051 2
10000055 1
10000055 7
10000056 1
10000056 7
10000057 1
10000057 9
10000058 1
10000058 9
10000058 3
10000059 1
10000059 9
10000059 9


...... .

From this result set, I want to list all entries in Row A for which Row A = Row B
and Row A+1 = Row B+1

As an example, please see the last two rows from the data set I have pasted. I want all such entries listed.

Thanks in advance.



madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-15 : 06:55:55

select a,b from your_table
group by a,b
having count(*)>1

Madhivanan

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

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-07-15 : 07:13:28
select a,b from (select row_number()over(partition by a,b order by a ) as rid , a, b from tablename)s where rid >1
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-15 : 07:18:46
quote:
Originally posted by bklr

select a,b from (select row_number()over(partition by a,b order by a ) as rid , a, b from tablename)s where rid >1


It seems OP is using SQL Server 2000 (from the title of the thread) where your query wont work

Madhivanan

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

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-07-15 : 07:20:16
deleted
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-07-15 : 07:21:16
k Thanks,Madhivanan

i haven't seen the title
hi, karthik it will works 2005 and above........
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-15 : 07:21:22
quote:
Originally posted by russell

deleted


What did you post?

Madhivanan

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-15 : 07:22:26
quote:
Originally posted by bklr

k Thanks,Madhivanan

i haven't seen the title
hi, karthik it will works 2005 and above........


No Problem

Madhivanan

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

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-07-15 : 07:22:37
same solution as bklr
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-15 : 07:24:05
quote:
Originally posted by russell

same solution as bklr



Dont delete the script. You can edit your reply to include this after the query




Madhivanan

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

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-07-15 : 07:25:35
quote:
Originally posted by madhivanan

quote:
Originally posted by russell

same solution as bklr



Dont delete the script. You can edit your reply to include this after the query




Madhivanan

Failing to plan is Planning to fail



lol
Go to Top of Page

kartikkumar84
Starting Member

7 Posts

Posted - 2009-07-15 : 08:27:38
Thank You!!
Go to Top of Page
   

- Advertisement -