Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8930527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:54:45+00:00 2026-06-15T08:54:45+00:00

Here is my data: ID FName LName data1 data2 1 John Doe xxx1 2

  • 0

Here is my data:

ID      FName   LName   data1   data2
1       John    Doe     xxx1    
2       John    Doe     xxx2    yyy2

And here is my desired result:

ID      FName   LName   data1   data2
1       John    Doe     xxx1    yyy2

In short, I have a table where are a lot of people, and that table is filled from multiple sources with different data and IDs. What I want is, for each duplicate I found and for each column in the table view if there is data present in that cell, then, if it exists, try to dump it to the oldest record for that person, if there is data, do nothing.

I don’t know if I made myself clear.

What should be the best approach to do this? Should I write a stored procedure or it can be done with a clever query I haven’t came up with yet?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:54:46+00:00Added an answer on June 15, 2026 at 8:54 am

    You can solve this with a query using joins and window functions:

    select nodups.id, nodups.fname, nodups.lname, d1.data1, d2.data2
    from
      (select min(id) as id, fname, lname from sample group by fname, lname) nodups
    left join
      (select fname, lname, min(data1) as data1
       from (select fname, lname
               , first_value(data1) over (partition by fname, lname order by id) as data1
             from sample where data1 is not null) d1x
       group by fname, lname
      ) d1 using (fname, lname)
    left join
      (select fname, lname, min(data2) as data2
       from (select fname, lname
               , first_value(data2) over (partition by fname, lname order by id) as data2
             from sample where data2 is not null) d2x
       group by fname, lname
      ) d2 using (fname, lname)
    order by id
    ;
    

    SQLFiddle

    Try testing this approach with your real data against Igor’s custom aggregate to see which performs better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of data saved in cookie, like this 1:good,2:accelent,3:bad,4:good,fname:Ahmad,lname:Riaz,title:Developer,org:Magiclamp,email:Riaz@khan.com here i
here is how I'm testing formset: >>>data = {'pfix-0-fname':'','pfix-0-lname':'','pfix-0-relation':'','pfix-0-dob_month':'','pfix-0-dob_day':'','pfix-0-dob_year':'','pfix-1-fname':'','pfix-1-lname':'','pfix-1-relation':'','pfix-1-dob_month':'','pfix-1-dob_day':'','pfix-1-dob_year':'','pfix-INITIAL_FORMS':'0','pfix-TOTAL_FORMS':'2'} >>>ffact = formset_factory(Form,extra=2) >>>fset =
I'm learning assembly and I have a very basic loop here segment .data msg:
I have a DataSet named dsView that contains data. Here is the code i
So i have php code to insert form data in a table. Here's the
Here is some example data: data = data.frame(series = c(1a, 1b, 1e), reading =
Here's a sample column of my data frame, RR is a header : RR
Here is my question: myd <- data.frame (V1 = paste (V, 1:1000), V2 =
Here is dataset: set.seed(123) myd <- data.frame (class = rep(1:4, each = 100), yvar
Here is the sample code, which produces interesting output: > gg<-data.frame(x=c(a,b),y=as.integer(c(1000,100000))) > gg x

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.