Solved

duplicates query oracle

Posted on 2014-09-03
3
528 Views
Last Modified: 2014-09-03
Hi - pretty new to SQL, but I have a table with an ID column with is apparently unique, i.e. there should be no more than 1 ID per " cost centre". The field of interest is called "code_combination_ID" in a table called apps.gl_code_combinations. Is there a query that can be run to ensure there is only 1 row of data per "code_combination_ID" or check for where there is more than 1 row of data per code_combination_ID?
0
Comment
Question by:pma111
[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
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 40300795
to find the values as such:
select code_combination_ID, count(*)
  from yourtable
group by code_combination_ID
having count(*) > 1

Open in new window


for getting more data from the columns, this article may help also:
http://www.experts-exchange.com/Database/Miscellaneous/A_3203-DISTINCT-vs-GROUP-BY-and-why-does-it-not-work-for-my-query.html
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40300796
once you have removed eventually any "duplicates", you could add a UNIQUE INDEX on the fields to ensure it will stay unique indeed.
0
 
LVL 49

Assisted Solution

by:PortletPaul
PortletPaul earned 250 total points
ID: 40300801
Hi, yes in SQL you can count rows "per something" by using a GROUP BY clause.
In addition, there is a HAVING clause which permits filtering on the calculated values of each "group by"
Like this:

select
     code_combination_ID
   , count(*) as row_count
from your_table
having count(*) > 1

This will list any "code_combination_ID" in that table that is referenced on more that 1 row.
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

724 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