Solved

duplicates query oracle

Posted on 2014-09-03
3
510 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
  • 2
3 Comments
 
LVL 142

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 142

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 48

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

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

How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
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 copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now