Solved

do not include duplicate

Posted on 2011-09-19
2
266 Views
Last Modified: 2012-05-12
use same table structure as related question

want all the columns for duplicate "dept_name"
   in the dept table.  do not include original row,  Only  include the duplicate row.
  the original row is the row that is entered first.
0
Comment
Question by:rgb192
2 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 36563781
If you want to use the dept_id that is the lowest as the original row, you can consider ROW_NUMBER() windowing function in SQL 2005.

SELECT {columns you want in final select}
FROM (
SELECT *, ROW_NUMBER() OVER(PARTITION BY dept_name ORDER BY dept_id) RN
FROM dept
) derived
WHERE RN > 1
;

You will get the duplicate rows. The original row is RN = 1, so those will be excluded.

Good luck!
0
 

Author Closing Comment

by:rgb192
ID: 36564733
thanks
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question