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 7087407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:40:14+00:00 2026-05-28T07:40:14+00:00

Greeting all… i have two table and their structure is identical… Table logDetail Date

  • 0

Greeting all…

i have two table and their structure is identical…

Table logDetail

Date              Time         CardID        Status  
2012-01-20        00:00:00     A1            ABSENT
2012-01-20        00:00:00     B1            ABSENT
2012-01-20        00:00:00     C3            ABSENT
2012-01-20        00:00:00     D1            ABSENT

Table preStatus

Date            Time        CardID        Status
2012-01-20     07:00:10     A1            COMING
2012-01-20     07:10:00     C3            COMING
2012-01-20     08:00:00     B1            LATE
2012-01-20     17:00:00     B1            BACK
2012-01-20     17:10:10     A1            BACK
2012-01-20     17:13:00     C3            BACK

After Merge

Date
2012-01-20     07:00:10     A1            COMING
2012-01-20     07:10:00     C3            COMING
2012-01-20     08:00:00     B1            LATE
2012-01-20     00:00:00     D1            ABSENT
2012-01-20     17:00:00     B1            BACK
2012-01-20     17:10:10     A1            BACK
2012-01-20     17:13:00     C3            BACK

How may i merge these two table because in table b there is duplicate records and when i do
a merge…

merge into logDetail as Target 
using preStatus as Source
on Target.L_Date=Source.L_Date
and Target.L_Time='00:00:00'
and Target.L_CardID=Source.L_CardID 
when matched then

update set Target.L_Status=Source.L_Status,
Target.L_Time=Source.L_Time
when not matched then
insert (L_Date,L_Time,L_CardID,L_Status) 
                           values(Source.L_Date,Source.L_Time,Source.L_CardID,Source.L_Status);

it said The MERGE statement attempted to UPDATE or DELETE the same row more than once

Any help is greatly appreciated.

  • 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-05-28T07:40:15+00:00Added an answer on May 28, 2026 at 7:40 am

    You don’t appear to want to merge the tables, since CardID is not a primary key.

    It looks like you want to retain the entries where Status = “COMING” even when there are new entries where stats = “BACK”.

    I suggest you do this in two steps, first do inserts of the preStatus data, then delete “ABSENT” rows where there exists “COMING” and “BACK” rows.

    /* Insert new data */
    insert logDetail
    select * from preStatus
    
    /* Delete Absent rows where there is a COMING or BACK row for the same item on the same day */
    Delete logDetail
    from logDetail ld1
    where 
        /* Absent rows only */
        ld1.time = '00:00:00'
    and ld1.Status = 'ABSENT'
    /*  And there must be a COMING or BACK row for the same card on the same day */
    and exists (
       select 1 from logDetail ld2
       where ld2.Date = ld1.Date
       and ld2.CardID = ld1.CardID
       and ld2.Time > '00:00:00'
       and ld2.Status <> 'ABSENT'
    )
    

    To remove rows for the same Date, CardID, and same Status, but where there is a later Time:

    Delete logDetail
    from logDetail ld1
    where 
    ld1.status in ('COMING', 'BACK')
    /*  COMING or BACK row only */ 
          /* for the same card on the same day, with a later time*/
    and exists (
       select 1 from logDetail ld2
       where ld2.Date = ld1.Date      
       and ld2.CardID = ld1.CardID
       and ld2.Status = ld1.Status
       and ld2.Time > ld1.Time
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greeting all. I have a SQL Server 2008 Express database with a table called
greeting all i am working on school project and i have a problem with
Greeting all. I have a SQL 2008 express database, lets name is tbl_Merchant, similar
Greetings all, I have a wxPython project (created with wxFormBuilder) that contains two panels,
Greeting, I have two levels of authentications in ASP.NET application. I have a Webadmin
Greetings all, I have a question. On my MOSS 2007 dev box, I created
Greetings all, I have a question. I am trying to build a parametrized query
Greetings to all! This is my first question here on stackoverflow. I have a
Greeting all, iptables -L gives the following output [root@ibmd ~]# iptables -L Chain INPUT
Greeting All, I want to achieve transparent persistence of Java objects through memory-mapped files

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.