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 8250759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:00:29+00:00 2026-06-08T00:00:29+00:00

I’m trying to select all records that have a duplicate value in the LASTNAME

  • 0

I’m trying to select all records that have a duplicate value in the LASTNAME column. This is my code so far

If EXISTS( SELECT name FROM sysobjects WHERE name = 'USER_DUPLICATES' AND type = 'U' ) 
    DROP TABLE USER_DUPLICATES
GO

CREATE TABLE USER_DUPLICATES
(
    FIRSTNAME VARCHAR(MAX),
    LASTNAME VARCHAR(MAX),
    PHONE VARCHAR(MAX),
    EMAIL VARCHAR(MAX),
    TITLE VARCHAR(MAX),
    LMU VARCHAR(MAX)
)
GO

INSERT INTO USER_DUPLICATES
(
    FIRSTNAME,
    LASTNAME,
    PHONE,
    EMAIL,
    TITLE,
    LMU
)
SELECT
    FIRSTNAME,
    LASTNAME,
    PHONE,
    EMAIL,
    TITLE,
    LMU
FROM TM_USER
GROUP BY
    FIRSTNAME,
    LASTNAME,
    PHONE,
    EMAIL,
    TITLE,
    LMU
HAVING COUNT(LASTNAME) > 1

It does not return any records. I changed the

HAVING COUNT(LASTNAME) > 1

to

HAVING COUNT(LASTNAME) > 0

and it returns all the records. I am also certain there are records with the same LASTNAME value. It is written using T-SQL on SQL Server

  • 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-06-08T00:00:32+00:00Added an answer on June 8, 2026 at 12:00 am

    Try this:

    SELECT
        a.FIRSTNAME,
        a.LASTNAME,
        a.PHONE,
        a.EMAIL,
        a.TITLE,
        a.LMU
    FROM TM_USER a
    INNER JOIN
    (
        SELECT LASTNAME
        FROM TM_USER
        GROUP BY LASTNAME
        HAVING COUNT(1) > 1
    ) b ON a.LASTNAME = b.LASTNAME
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I know there's a lot of other questions out there that deal with this

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.