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

  • SEARCH
  • Home
  • 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 Sql Server 2000 I want to find out the duplicate record in the
Using SQL Server 2000 I am trying to use this command in Query Analyzer
I'm trying to migrate from sql server 2000 to mysql by using DTS. That's
I'm using SQL Server 2000 and i'm trying to run an update query to
Using sql server 2000, I would like to take my production data and put
Using SQL Server 2000 Table PersonID Date 001 11-02-2009 002 11-02-2009 003 11-02-2009 001
Using SQL Server 2000 My Query. SELECT (Format(IIf(CLng(OutTime) > 180000, CDate('18:00:00'), CDate(Format(OutTime, '00:00:00'))) -
I'm using SQL Server 2000 to print out some values from a table using
I am using SQL Server 2000 and I have two databases that both replicate
We are using SQL Server 2000 and have to move data across servers to

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.