?
Solved

duplicates query oracle

Posted on 2014-09-03
3
Medium Priority
?
533 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 1000 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 1000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Suggested Courses

765 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