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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:27:34+00:00 2026-05-27T10:27:34+00:00

I am using VS2005 C# and SQL Server 2005. I want to form an

  • 0

I am using VS2005 C# and SQL Server 2005. I want to form an SQL query with the following condition:

Check for duplicated user in Table1 tb1 where tb1 has more than one [Emp.Name]

EDIT:

Simply saying, if I am only checking duplicate for [emp name], there’s no way I can select [employeeID]?

Because if I use

INSERT INTO DuplicateUserInTb1(EmployeeID, [Emp Name], Status, Issue)
SELECT tb1.EmployeeID, tb1.[Emp Name], 'Active', 'Duplicated user in Table1'
FROM Table1 tb1 GROUP BY tb1.[employeeID], tb1.[emp name] HAVING COUNT(tb1.[emp name]) >1 

I will not be able to see any duplicated [emp name] rows inserted.

However, if I use

INSERT INTO DuplicateUserInTb1([Emp Name], Status, Issue)
SELECT tb1.EmployeeID, tb1.[Emp Name], 'Active', 'Duplicated user in Table1'
FROM Table1 tb1 GROUP BY tb1.[emp name] HAVING COUNT(tb1.[emp name]) >1

I am able to retrieve duplicated [emp name], however, without [employeeID].


EDITED:

Working on these 2 queries provided by Zohalib and Michal Powaga respectively:

 INSERT INTO DuplicateUserInTb1(EmployeeID, [Emp Name], Status, Issue) 
 select t.emp_id, t.empname, t.active, t.du 
from (select s1.emp_id, s1.empname,'Active' as active, 'Duplicate User' as du,
ROW_NUMBER() OVER (PARTITION BY s1.empName ORDER BY s1.empName) as rowNum 
from table s1, 
(select emp_name, count(*)
 from table 
 group by emp_name
 having count(*) > 1) s2
 where s1.emp_name = s2.emp_name 
) t where t.rowNum = 1

Error : No column was specified for column 2 of ‘s2


insert into DuplicateUserInTb1(EmployeeID, [Emp Name], Status, Issue)
select employeeID, [emp name], 'Active', 'Duplicated user in Table1'
from Table1 t1
join (
    select [emp name]
    from Table1
    group by [emp name]
    having count(*) > 1
) t on t1.[emp name] = t.[emp name]

Error: *Ambiguous column name '[Emp name]'


Would appreciate any help, thank you.

  • 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-27T10:27:35+00:00Added an answer on May 27, 2026 at 10:27 am

    When you use Group By clause, then your select clause can only contain columns

    which are either mentioned in group by clause

    Or aggregate functions, eg Count, SUM e.t.c
    http://www.w3schools.com/sql/sql_groupby.asp

    Moreover, in your query, you are inserting values in three columns, but your select clause is selecting four values, should’nt this be a problem ?

    try following query to insert duplicates based on empname

        INSERT INTO DuplicateUserInTb1(EmployeeID, [Emp Name], Status, Issue) 
    select t.emp_id, t.empname, t.active, t.du 
    from (select s1.emp_id, s1.empname,'Active' as active, 'Duplicate User' as du, ROW_NUMBER() OVER (PARTITION BY s1.empName ORDER BY s1.empName) as rowNum 
    from table s1, 
    (select emp_name, count(*) as counts
     from table 
     group by emp_name
     having count(*) > 1) s2
     where s1.emp_name = s2.emp_name 
    ) t where t.rowNum = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using VS2005 C# and SQL Server 2005. I have a SQL Query
I am using VS2005 C# and SQL Server 2005. I am currently using user
I am using VS2005 and SQL Server 2005. I am trying to execute multiple
I am using VS2005 and SQL Server 2005. I am trying to execute multiple
I am using VS2005 C# and SQL Server 2005. Currently I am able to
I am using VS2005 C# and SQL Server 2005. I am currently doing an
I am using VS2005 C# 2.0 and SQL Server 2005. I am referring to
I am using VS2005 C# .NET 2.0 and SQL Server 2005. Are there any
I am using VS2005 C# and SQL Server 2005. I have a GridView and
I am using VS2005 C# and SQL Server 2005. I have an Excel file

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.