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

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 December 15th, 2004, 03:15 PM
sanctos2003 sanctos2003 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 95 sanctos2003 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 29 m 24 sec
Reputation Power: 5
Problems with slight differences in two 'duplicate' records

I am having a tricky problem. I have records in a database that are in pairs based on a composite key (3 fields).

Some of the pairs are completely identical, meaning each and every field in those pairs are the same. Some, however have a slight difference, in that one of the fields was updated and does not make the pairs truly identical.

Let's assume a table like this:

Table Name - FOOD
Fields: (RecID, Name, Type, Color, Size)

And the table structure is laid out like so:

1, Apple, Fruit, Red, Small
1, Apple, Fruit, Green, Small
2, Grape, Fruit, Purple, Small
2, Grape, Fruit, Purple, Small
3, Pineapple, Fruit, Brown, Small
3, Pineapple, Fruit, Brown, Large


What I want to do is write a query that will show me only the pairs that have changes in them. When I run the query I would want to see the following:

1, Apple, Fruit, Red, Small
1, Apple, Fruit, Green, Small
3, Pineapple, Fruit, Brown, Small
3, Pineapple, Fruit, Brown, Large

I would not want to see #2 (Grapes) because the records are identical.

Might I have to use a self join? Any help would be cool.

Sanctos

Reply With Quote
  #2  
Old December 15th, 2004, 04:20 PM
A2k's Avatar
A2k A2k is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 166 A2k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 h 44 m 10 sec
Reputation Power: 4
Select Distinct RecID, Name, Type, Colour, Size
FROM table

Reply With Quote
  #3  
Old December 30th, 2004, 08:50 AM
Dumbo Dumbo is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 29 Dumbo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 27 m 31 sec
Reputation Power: 0
Select Distinct RecID, Name, Type, Colour, Size FROM table

WON'T work!!!!
It will display all the lines that are not identical, but also display the ones that are the same one time

If I read the problem correctly this is not wanted.

What you need is something like this:

select * from table a where exists (select * from table b where b.row_id=a.row_id and (a.name<>b.name or a.type<>b.type or a.colour<>b.colour or a.size<>b.size))

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Problems with slight differences in two 'duplicate' records


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 1 hosted by Hostway
Stay green...Green IT