Solved

A fairly simple SQL question

Posted on 2013-10-24
4
518 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 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
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.

636 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