Solved

Checking for duplicate valiues in table

Posted on 2014-03-01
2
116 Views
Last Modified: 2014-03-07
I have a table Trn_OrderItemAdvise which has fields Episodeid, Adviseserialno

For each episode, we have n no of Adviseserialno which is incrementing by 1

For ex Epsiodeid 1 has adv serial no as follows

   1    1
   1     2
    1    3
   1     4
         etc
This advise serialno gets reset for each episode
i,e  episode id 2 has again adv serial no starting from 1, 2 ,3 ......

Now i have to find For each episode any duplicate adviseserialnos are present

i, e if episode 2 has 1,2,2,3,4, ...   i need to have  
  episode 2 selected with count  of 1 duplicate rows

Can experts advise on how to do this
0
Comment
Question by:venkataramanaiahsr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 39897277
I think something like this will work.

SELECT Episodeid, Adviseserialno, COUNT(Adviseserialno) as counter
FROM  Trn_OrderItemAdvise
GROUP BY Episodeid
HAVING COUNT(Adviseserialno) > 1
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 39897384
I think something like this will work.
Unfortuantely, that is going to produce an error.  You cannot include a column (Adviseserialno) in a SELECT that is not in an aggregate function and is not included in the GROUP BY clause.

I think you mean (no points please):
SELECT  Episodeid,
        Adviseserialno,
        COUNT(*) AS counter
FROM    Trn_OrderItemAdvise
GROUP BY Episodeid, Adviseserialno
HAVING  COUNT(*) > 1

Open in new window

0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

728 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