Solved

Oracle: Duplicate data search query

Posted on 2015-02-24
6
194 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
Comment Utility
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
Comment Utility
Looks good..  Let me keep this open for further testing.  Thank you
0
 

Author Comment

by:Maliki Hassani
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
>>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
Comment Utility
Brilliant... lol
0
 

Author Closing Comment

by:Maliki Hassani
Comment Utility
Thank you!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
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 explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

771 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

15 Experts available now in Live!

Get 1:1 Help Now