Solved

Checking for duplicate valiues in table

Posted on 2014-03-01
2
115 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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

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 …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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