Duplication

Last post 11-05-2007 4:34 AM by Adriaan. 11 replies.
Page 1 of 1 (12 items)
Active Topics My Discussions Unanswered Sort Posts: Previous Next
  • 11-03-2007 12:57 AM

    • Jeena
    • Top 500 Contributor
    • Joined on 10-17-2007
    • India
    • Posts 30

    Duplication

    Hi all,

    Im having 12 tables in a database. There are duplications inside the tables,also outside the tables. One record in one table may be duplicated in other table in the database.In this situation which query can i give.Pls help.

    Filed under:
  • 11-03-2007 1:41 AM In reply to

    Re: Duplication

    Can you post some sample data with expected result?

    Madhivanan

    Failing to plan is Planning to fail
  • 11-03-2007 1:50 AM In reply to

    • Jeena
    • Top 500 Contributor
    • Joined on 10-17-2007
    • India
    • Posts 30

    Re: Duplication

    Hi,
    The duplication is for my mobileno.Some times date and year too be duplicated.
    In the same day itself one can send has many sms as they want. But i want a record in which any one of there message is present.
    I need it in the above format itself.Not the mobileno or message alone.Mobileno must be unique,

    I wil give an eg:
    No Mess Date Year
    1234 Hi 10Aug 2007
    5487 Hi 22Aug 2007
    1234 He 22Aug 2006

    In this case the result shuld be like

    1234 ---- ----- -----
    5487 Hi 22Aug 2007

    Any one record of No 1234.

    Hope u can help me.
    Thanks in advance

    Regards
    Jeen
    Filed under:
  • 11-03-2007 2:03 AM In reply to

    Re: Duplication

    Select mobileno,min(message) as message, min(date) as date from table

    group by mobileno

    Madhivanan

    Failing to plan is Planning to fail
  • 11-03-2007 2:20 AM In reply to

    • Jeena
    • Top 500 Contributor
    • Joined on 10-17-2007
    • India
    • Posts 30

    Re: Duplication

     

    The above i had given is a sample data. I have 14 colums.

     

    2009489  E     NULL    0  NULL NULL NULL NULL 5/15/2007 2007 6051 NULL NULL NULL
    2009489  E     NULL    0  NULL NULL NULL NULL 5/19/2007 2007 6051 NULL NULL NULL
    2009489  E     NULL    0  NULL NULL NULL NULL 5/2/2007 2007 6051 NULL NULL NULL
    2009489  E     NULL    0  NULL NULL NULL NULL 5/20/2007 2007 6051 NULL NULL NULL
    2009489  Hi     NULL    0  NULL NULL NULL NULL 5/3/2007 2007 6051 NULL NULL NULL
    2009489  E     NULL    0  NULL NULL NULL NULL 5/4/2007 2007 6051 NULL NULL NULL
    2009489  E     NULL    0  NULL NULL NULL NULL 5/6/2007 2007 6051 NULL NULL NULL
    2009489  E      NULL    0  NULL NULL NULL NULL 5/7/2007 2007 6051 NULL NULL NULL
    2009489  Hello  NULL   0  NULL NULL NULL NULL 5/9/2007 2007 6051 NULL NULL NULL

    The above is my original data. Here only date,message is different.wen i give distinct *all these records comes.But i want only one record from this that gives unique mobileno.While selecting i should get in this same format.

    Thank U in Advance.

    Jeen

    Filed under:
  • 11-03-2007 3:10 AM In reply to

    Re: Duplication

    You need to extend the query I suggested

    Select mobileno,min(col2) as col2, min(col3) as col3, min(col4) as col4..... min(col14) as col14 from table group by mobileno

    Madhivanan

    Failing to plan is Planning to fail
  • 11-03-2007 3:17 AM In reply to

    • Jeena
    • Top 500 Contributor
    • Joined on 10-17-2007
    • India
    • Posts 30

    Re: Duplication

    Thanks a lot...Smile

    Just one more doubt.If i have the same mobileno in another table in the same databse.Which query can i give??

    Thanks

    Jeen

  • 11-03-2007 8:50 AM In reply to

    Re: Duplication

    Jeena:

    Thanks a lot...Smile

    Just one more doubt.If i have the same mobileno in another table in the same databse.Which query can i give??

    Thanks

    Jeen

    You need to join the above query with table2 matching mobileno

    Madhivanan

    Failing to plan is Planning to fail
  • 11-03-2007 8:54 AM In reply to

    • Jeena
    • Top 500 Contributor
    • Joined on 10-17-2007
    • India
    • Posts 30

    Re: Duplication

     

    Hi.. In the above query if i want to delete the duplicated mobileno from other table,can i give delete instead of select?

    Which join should i give?Inner,Outer,Left ....

    Thank u.

    Jeen

  • 11-03-2007 2:31 PM In reply to

    • satya
    • Top 10 Contributor
    • Joined on 11-05-2002
    • United Kingdom
    • Posts 22,567
    • Microsoft MVP
      Moderator

    Re: Duplication

    You can also sort and select eliminate duplicates. But that only eliminates dups from your input data. To only add rows that don't already exist, the lookup is the way as you described.
    Also blogged about this as well:
    http://sqljunkies.com/WebLog/knight_reign/archive/2005/03/21/9368.aspx kubj,

    -Satya S K J

    SQL Server MVP



    Knowledge is Power, you will gain by sharing it. SSQA.net - Invisible contributions to the users & visible success in SQL Community.
  • 11-03-2007 11:26 PM In reply to

    • Jeena
    • Top 500 Contributor
    • Joined on 10-17-2007
    • India
    • Posts 30

    Re: Duplication

    Hi..

    Im not going to insert a single value into that tables. All that i want to do is to eliminate duplicate records from other tables.A value(in this case mobileno) in one table should not be in the other.

    Thanks In advance

    Jeen 

    Filed under:
  • 11-05-2007 4:34 AM In reply to

    Re: Duplication

    I'm having problems trying to understand a requirement where a key value may only occur in one table, and at the same time the key is in use for a number of tables. Could be poor normalization, or the lack of a "status" type of column.

    Other than that, sounds like you need some IF EXISTS checks in insert/update triggers.

Page 1 of 1 (12 items)
Active Topics   My Discussions    Unanswered Posts


© 2000 - 2007 vDerivatives Limited All Rights Reserved.