Solved

do not include duplicate

Posted on 2011-09-19
2
273 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS SQL page split per second is high 19 106
SQL Server 2012 express 24 40
Replace Dates in query 14 51
SQL Server Insert where not exists 24 46
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 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