Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Get only one matching row for each name from several address rows.

Total Hit ( 1462)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


This is the fastest way to get say only one matching address row for each person out of a set of duplicates. This logic assumes that you do not care which address row you want to display. It can be easily extended to include other checks say based on the last added address row etc.

Click here to copy the following block
create table #P (
 Name varchar( 30 ) ,
 Address varchar( 30 ) ,
 Phone varchar( 30 )
)
insert #p values (
'John Smith, M.D.''123 East St',     '999-555-1212')
insert #p values (
'John Smith,M.D.',  '123 East Street''999-555-1212')
insert #p values (
'John Smith, MD',   '123 East St',     '999-555-1212')

insert #p values (
'Jim Smith, M.D.''123 Weest St',     '364-879-0657')
insert #p values (
'Jim Smith,M.D.',  '123 wee Street''364-879-0657')

insert #p values (
'Raly JunkD',   '83 NW St',     '987-754-1243')

insert #p values (
'Bill Gtea'NULL ,     '487-348-9082')
insert #p values (
'Bill Gtea',  '67 Village Blvd''487-348-9082')

-- You can concatenate other columns also to determine uniqueness
select * from #p t1
where Not exists(SELECT * FROM #p t2
        WHERE t1.Phone = t2.Phone And
           -- COALESCE will take care of NULL in address column.
           t2.Name + COALESCE(t2.Address, '') >
             t1.Name + COALESCE(t1.Address, ''))


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.