SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 5th, 2003, 04:14 AM
gulshan gulshan is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 9 gulshan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Find common rows

Hy, I have a query which return the following result. That is a list of rows with 2 columns. Some numbers are common in certain rows. I need to combine all common numbers in 1 row.
If I have the following rows:
ID | DUP_ID
"30007";"30008";
"30005";"30007";
"30006";"30011";
"30004";"30006";
"30001";"30006";
"30012";"30013";

my final result should be:

30007; 30008; 30005
30006; 30011; 30004; 30001
30012; 30013

How to achieve this.

thanks in advance

gul

Reply With Quote
  #2  
Old November 5th, 2003, 07:14 AM
Silian's Avatar
Silian Silian is offline
Gogga
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: A long, long time ago, in a galaxy, far, far away...
Posts: 34 Silian User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
You can do this by using two queries:
select distinct ID from table --gets the first ID's

select distinct DUP_ID from table where DUP_ID not in (select distinct ID from table)
--gets those ID's that weren't in the first batch

Or you can declare a table variable (with one column), read all of the ID's and DUP_ID's into it, and just select the distinct ID's

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Find common rows


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway