SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 t-sql avod a cartesian product
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jassie
Constraint Violating Yak Guru

296 Posts

Posted - 12/24/2012 :  16:45:49  Show Profile  Reply with Quote
For a customer, I need to load data from excel 2010 spreadsheets into a sql server 2008 r2 database for a one time set of adhoc queries. I will then run queries to obtain to look at the data based upon the user requirements.

The problem with the data is there is alot of duplicate data within different rows within the same table. When I join the various tables together, I get a cartesian product.
I am trying to determine how to run the queries I need to run without getting the cartesian product.

There are 3 tables which are: 1. a claims table by client number that has the duplicate data wtihin some of the rows. 2. a price table and 3. an authorizagtion table.

I am thinking of loading the data into temp tables in a way that the data will not be duplicated. If this is a possbility, can you tell me how to accomplish this goal?

If you have any other suggestions, can you show me code on how to accomplish this goal?

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 12/25/2012 :  09:04:36  Show Profile  Reply with Quote
Wouldn't it be good to look at excel as to why you are getting duplicate data in same table? You can use distinct to avoid duplicates but we will need some sample data and expected output as to what exactly you are asking for?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 12/26/2012 :  00:00:44  Show Profile  Reply with Quote
you need explain definition of duplicates. Does duplicate means entire row being duplicate or are you interested in only set of column values? Based on that then we can apply a logic so as populate only distinct set onto tables. Showing some sample data would make it clear for us on what exactly you're after

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jassie
Constraint Violating Yak Guru

296 Posts

Posted - 12/26/2012 :  11:09:25  Show Profile  Reply with Quote
I am only interested in two columns. I do not care about the rest of the columns in each row.
Go to Top of Page

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 12/26/2012 :  11:46:51  Show Profile  Reply with Quote
Read this :
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 12/27/2012 :  00:03:06  Show Profile  Reply with Quote
quote:
Originally posted by jassie

I am only interested in two columns. I do not care about the rest of the columns in each row.


ok in that case how do you want row to be retrieved for each of the groups having same value for two columns? do you've primary key (unique value) column in table to determine order? do you need earliest,latest or random row out of each group?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000