Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5957929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:28:14+00:00 2026-05-22T18:28:14+00:00

I am using SQL-Server 2000 and am trying to find duplicates with certain conditions.

  • 0

I am using SQL-Server 2000 and am trying to find duplicates with certain conditions. Someone here helped me earlier with the duplicate part which was great, however, I can’t figure out how to filter the duplicated cases further.
I need to move the “where” statement to the subquery so that I only get contractor duplicated names as opposed to all duplicated names which is what’s happening with this code (the code is first finding all duplicates and then filtering out the contractors and I’d like it to do the opposite). The problem is that I’m mixing it into an aggregate statement and it’s giving me an error. I tried to put in another subquery within the subquery but it still gave me an error.
Any help is appreciated. Here’s a simpler (I’m learning) version of the code:

SELECT DISTINCT(c1.contactid) as 'ContactID', c1.lastname as 'Last Name', c1.firstname as 'First Name'
FROM contacts c1 INNER JOIN (SELECT lastname, firstname FROM contacts group by lastname, firstname     
HAVING count(*)>1)
dups on c1.lastname=dups.lastname and c1.firstname=dups.firstname
WHERE (c1.contractor=1)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:28:15+00:00Added an answer on May 22, 2026 at 6:28 pm
    Select C.contactid As ContactID
        , C.LastName As [Last Name]
        , C.FirstName As [First Name]
    From contacts C
           Inner Join   (
                       Select C1.LastName, C1.FirstName
                       From contacts As C1
                       Where C1.contractor = 1
                       Group By C1.LastName, C1.FirstName
                       Having Count(*) > 1
                       ) As dups
             On C.LastName = dups.LastName
                And C.FirstName = dups.FirstName
    Where C.contractor = 1
    

    You are going to need the filter on contractor = 1 in both the subquery and the outer query. Otherwise, you might return people that happen to have the same name as a contractor and are duplicated.

    Also, you do not need the Distinct keyword if ContactId is the primary key of the Contacts table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Vb.net/SQL Server 2000 updating a row via a gridview/sqldatasource Stored proc: @ISTag varchar(10),
Using SQL Server 2000 and Microsoft SQL Server MS is there a way to
Using SQl Server 2000 I have a stored procedure that joins 2 tables and
I'm using SQL Server 2000 and my ERP vendor has used a Text datatype
I have developed an application using Entity Framework , SQL Server 2000, Visual Studio
Using SQL Server, I'm trying to query a kind of averaged count from a
does anyone has any experience of installing Liferay using SQL Server as database ?
I'm using SQL Server 2005 Express as a database in my desktop application. My
I'm using SQL Server 2005. I have a temporary sorted table ( Table_A )
I'm using SQL server 2008 I have the following SQL getting all dates between

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.