Solved

duplicates query oracle

Posted on 2014-09-03
3
500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

744 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

13 Experts available now in Live!

Get 1:1 Help Now