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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Comparing rows

Author  Topic 

RDOllc
Starting Member

2 Posts

Posted - 2011-03-11 : 18:00:11
Hello all, I have a large database of user profile data. I need to be able to compare 1 row against all of the other rows, for all columns to find the best match.
There are around 30 columns of data for each row. I need to be able to find the 5 best matching rows.
I.E.
Row 1 matches on 2 column's
Row 2 matches on 12 column's
Row 3 matches on 7 column's
Row 4 matches on 4 column's
Row 5 matches on 9 column's
Row 6 matches on 23 column's
Row 7 matches on 29 column's

In the end it will show me the data for rows 7, 6, 2, 5, 3

Now to make it even harder, Some of the columns are bit, some are varchar. Some of them may be a direct match, some will need to search if the column for row2 contains the text of row 1.

FYI, this is on a web app using asp.net if that matters.
Thank you!

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-03-11 : 18:21:47
Possible solution here: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=157456

There's no real shortcut for comparing the columns using the structure you have.
quote:
some will need to search if the column for row2 contains the text of row 1
I have no idea what this means. It's best to post your actual table structure, some sample data, and the expected results.
Go to Top of Page

RDOllc
Starting Member

2 Posts

Posted - 2011-03-11 : 19:08:27
Thank you but that link dosn't help me.

Is there a way to have a stored procedure to:
A) Create a temp table
B) Store the uniqueidentifier of each row in the primary DB
C) View all columns for the 1st users row
D) find all rows that match column1 then store "1" in the "count" column for that uniqueidentifier in the temp DB
E) repeat through all columns of the database, adding a number to the count for each match
F) return the uniqueidentifier for the top 5 highest counts
Go to Top of Page
   

- Advertisement -