Avatar of HLRosenberger
HLRosenberger
Flag for United States of America asked on

Help with SQL - query name records

I have a table of employees, first, middle and last name columns along with other info.  I want to query a list of all records where the first, middle and last name are the same, grouping by the same.  There are also two other columns I want returned in the results, call them ID1 and ID2, and that will be different for each record. -  How can I do this?
Microsoft SQL Server 2005Microsoft SQL Server 2008Microsoft SQL Server

Avatar of undefined
Last Comment
Jim Horn

8/22/2022 - Mon
Jim Horn

Based on the requirements in your question, give this a whirl...
SELECT firstname, middlename, lastname, ID1, ID2
FROM yourtable 
WHERE  firstname = middlename AND middlename = lastname

Open in new window


>I want to query a list of all records where the first, middle and last name are the same, grouping by the same.
if there's anything missing, please spell it out.  I suspect that the above is missing some detail.
HLRosenberger

ASKER
I did not articulate my  question correctly.  Let me use an example; say I have these records:

Harold L Rosenberger  123  456
Harold L Rosenberger 111 333
Mary Jones 333 444
George Washington 333 444
George Washington 555 666
George Washington 123 877
George R Washington 155 876
Gary Lee Rogers 555 120

I want these records returned:

Harold L Rosenberger  123  456
Harold L Rosenberger 111 333
George Washington 333 444
George Washington 555 666
George Washington 123 877
ASKER CERTIFIED SOLUTION
Jim Horn

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
HLRosenberger

ASKER
that works, except for one case, where the middle name is NULL.   How could I modify to handle this?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Jim Horn

yeah, can't do a NULL = NULL, so a simple ISNULL conversion will work.  
Change 'x' to whatever floats your boat.
I modified the code block above to keep the solution in one comment.
HLRosenberger

ASKER
Thanks!!
Jim Horn

Thanks for the grade.  Good luck with your project.  -Jim
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.