Solved

A fairly simple SQL question

Posted on 2013-10-24
4
457 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
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
Steve Wales earned 500 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 31

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Read about achieving the basic levels of HRIS security in the workplace.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

746 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

8 Experts available now in Live!

Get 1:1 Help Now