Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

A fairly simple SQL question

Posted on 2013-10-24
4
Medium Priority
?
526 Views
Last Modified: 2013-10-24
I have an Oracle table like so:

dealer, dealnum, lastname, firstname, emplid, date

I believe that in a few cases the emplid for a given person has changed. In this example Joe Smith's emplid changed from 00000 to 12345:

dealer dealnum lastname firstname emplid, date
10001 7700 SMITH JOE 12345 2013-10-24
10001 4533 SMITH JOE 00000 2013-07-01

Open in new window


How can I determine the dealer, dealnum, lastname and firstname of rows where there is more than one emplid associated with a given dealer+lastname+firstname combination?

In other words I'm looking for people whose emplid has changed over time.

I know how to use row_number() with group by to get the most recent row for a given person, which would give me the current value, 12345 in this example. But that's expensive and I want first to size up how many such cases there are.
0
Comment
Question by:FelineConspiracy
[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
4 Comments
 
LVL 23

Accepted Solution

by:
Steve Wales earned 1500 total points
ID: 39597870
select dealer, lastname, firstname, count(*)
from mytable
group by dealer, lastname, firstname
having count(*) > 1

Open in new window


This will show you rows where that combination of columns appears more than once.
0
 
LVL 32

Expert Comment

by:awking00
ID: 39598564
What do you want to do with the information? Delete or update the earlier records or something else?
0
 

Author Comment

by:FelineConspiracy
ID: 39599047
No deletes or updates. To oversimplify a bit: Someone will be doing some manual updates, once we're confident about the data to act on. This query is part of some precautions I'm taking to avoid updating rows where, for example, someone has had multiple valid emplids at different times, as we cannot necessarily know which one to keep. So I'll just screen those people out.
0
 

Author Closing Comment

by:FelineConspiracy
ID: 39599049
Thank you.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to recover a database from a user managed backup

715 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