SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2005
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can I create this table?

    Hello,

    I have 2 tables that I need to make into one.

    This first table is called mct, contains all the products name, ids, descriptions, etc. The problem with this table is that it was built using a feed and contains many duplicate products.

    The second table, mct2, contains only the product names but there are no duplicates.

    Okay, so how can I make this one nice, neat table without the duplicates. Or how can I delete the duplicates from the first table? I have tried building a table using a select/ distinct statement but can't get it figured out.

    Thanks

  2. #2
    SitePoint Evangelist pompopom's Avatar
    Join Date
    Feb 2004
    Location
    Huldenberg (Belgium)
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why don't you make a SELECT query where you look for the id's of all the products with the same product name.

    Then you do a DELETE query for all the id's except one...
    The Path of excess leeds to the tower of wisdom (W. Blake)

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2005
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, I have tried something similar with the following:

    SELECT mctid FROM `mct`, mct2 WHERE mct_title= mct2_title

    This just gives me all the products in the table. I am not really sure how to write the select statement to get just the ones that have matching names.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    please do a search in the Databases forum, we've answered the "how do i remove all duplicates except one" several times

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Zealot
    Join Date
    Dec 2005
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies, I really appreciate it.

    I was able to accomplish it by deleting the duplicates from table mct like so:

    Code:
    delete
    from mct
    group by mct_title
    having count(*) > 1
    Thanks again

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by affmark
    I was able to accomplish it
    i hope you took a backup first
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Zealot
    Join Date
    Dec 2005
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I did. Sorry, I should have mentioned that in the above post.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •