Solved

Oracle: Duplicate data search query

Posted on 2015-02-24
6
201 Views
Last Modified: 2015-02-24
Experts,

I am trying to identify (return records) for records that meet a specific criteria.  For example.  I have a maintenance table that shows the ticket details for each maintenance. For each device that this being worked on during the maintenance will create a record having the same GUI ID.  

What I would like to do is identify for EACH day device names that are showing up more than once.  This will help me de-conflict maintenance before approving them.

Here is the query that I am trying to modify:

SELECT CM.CHANGE_ID,CM.PRIMARY_START_DATE_TIME,DE.DEVICE_NAME
from CHANGE_REQUEST CM INNER JOIN RELATED_DEVICES DE ON CM.GUI_ID=DE.GUI_ID AND DE.RECORD_STATUS = 0
   AND CM.PRIMARY_START_DATE_TIME >= TO_DATE('1/1/2015','MM/DD/YYYY') 
     AND CM.PRIMARY_START_DATE_TIME < TO_DATE('2/1/2015','MM/DD/YYYY') 

Open in new window


See example.  The highlighted rows are the only records I want to return, since  both change id's are on the same day and the device Name match.

Data-example.xlsx

Thank you
0
Comment
Question by:Maliki Hassani
  • 4
  • 2
6 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 40628779
Untested but try this:

select CHANGE_ID, CHANGE_ID, DEVICE_NAME
from (
SELECT CM.CHANGE_ID,CM.CHANGE_ID,DE.DEVICE_NAME,
count(*) over(partition by CM.PRIMARY_START_DATE_TIME,DE.DEVICE_NAME) row_count
from CHANGE_REQUEST CM INNER JOIN RELATED_DEVICES DE ON CM.GUI_ID=DE.GUI_ID AND DE.RECORD_STATUS = 0
   AND CM.PRIMARY_START_DATE_TIME >= TO_DATE('1/1/2015','MM/DD/YYYY')
     AND CM.PRIMARY_START_DATE_TIME < TO_DATE('2/1/2015','MM/DD/YYYY')
)
where row_count > 1
0
 

Author Comment

by:Maliki Hassani
ID: 40628797
Looks good..  Let me keep this open for further testing.  Thank you
0
 

Author Comment

by:Maliki Hassani
ID: 40628836
I see where it is looking for a match when records have the same exact primary start date time.  How would I change this to show tickets that are within the same date?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40628840
>>How would I change this to show tickets that are within the same date?

...
count(*) over(partition by trunc(CM.PRIMARY_START_DATE_TIME),DE.DEVICE_NAME) row_count
...
0
 

Author Comment

by:Maliki Hassani
ID: 40628841
Brilliant... lol
0
 

Author Closing Comment

by:Maliki Hassani
ID: 40629247
Thank you!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
New and Previous Values in a Query 7 30
any step by steps guide on how to install Oracle 12c on Windows 10 8 58
sum of columns in a row in oracle 3 32
Trouble with <> 2 20
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

856 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