SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Compare two data sets-- Please help


Compare two data sets-- Please help

Author
Message
Ram:)
Ram:)
SSC Veteran
SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)

Group: General Forum Members
Points: 207 Visits: 438
Hi,

I have a scenario while comparing the data between two data sets.

CREATE TABLE DATA
(ID BIGINT,
CODE VARCHAR(100),
CNAME VARCHAR(100))

TRUNCATE TABLE DATA
INSERT INTO DATA
SELECT 1,'INSURANCE','MONTHLY'
UNION
SELECT 1,'E-RD','MONTHLY'
UNION
SELECT 1,'RD','MONTHLY'
UNION
SELECT 2,'INSURANCE','BI-MONTHLY'
UNION
SELECT 2,'E-RD','QUARTERLY'
UNION
SELECT 2,'RD','MONTHLY'
UNION
SELECT 3,'INSURANCE','YEARLY'
UNION
SELECT 3,'E-RD','MONTHLY'
UNION
SELECT 3,'RD','MONTHLY'
UNION
SELECT 3,'FD','MONTHLY'
UNION
SELECT 4,'INSURANCE','YEARLY'
UNION
SELECT 4,'E-RD','MONTHLY'
UNION
SELECT 4,'RD','MONTHLY'


CREATE TABLE NEW_DATA
(CODE VARCHAR(100),
CNAME VARCHAR(100))
INSERT INTO NEW_DATA
SELECT 'INSURANCE','YEARLY'
UNION
SELECT 'E-RD','MONTHLY'
UNION
SELECT 'RD','MONTHLY'



Here I need to compare data from table NEW_DATA with table DATA and need to pick id from Table DATA which have the same set of records.. In the above scenario id 3 and 4 can be compared with NEW_DATA but id 4 only has same set of data..

Please help me with query

:-)
Phil Parkin
Phil Parkin
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19734 Visits: 20462
What results do you want to see, based on your sample data?


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Ram:)
Ram:)
SSC Veteran
SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)

Group: General Forum Members
Points: 207 Visits: 438
I want to get the id from DATA table which has exact data in NEW_DATA table

:-)
Mark Cowne
Mark Cowne
Hall of Fame
Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)Hall of Fame (3.2K reputation)

Group: General Forum Members
Points: 3235 Visits: 24128
Maybe this?


SELECT d.ID
FROM DATA d
LEFT OUTER JOIN NEW_DATA n ON n.CODE = d.CODE AND n.CNAME=d.CNAME
GROUP BY ID
HAVING COUNT(*) = COUNT(n.CNAME);



____________________________________________________

Deja View - The strange feeling that somewhere, sometime you've optimised this query before

How to get the best help on a forum

http://www.sqlservercentral.com/articles/Best+Practices/61537




Ram:)
Ram:)
SSC Veteran
SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)SSC Veteran (207 reputation)

Group: General Forum Members
Points: 207 Visits: 438
Such a simple logic. Thanks.

:-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search