Solved

duplicates query oracle

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

726 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