SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: SQL query

  1. #1
    SitePoint Enthusiast codlib's Avatar
    Join Date
    Jan 2007
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question SQL query

    Hi

    I have two mysql tables 'letter' and 'lettercopy' letter will daily populated with records. Lettercopy is a copy of letter table and once in a week it should copy the new records from letter to lettercopy. The records in letter will not get updated or deleted once inserted. I am looking for some kind of incremental copy. Can anyone tell me how the SQL should be. I tried insert ignore but it is not working.

    Below is my table syntax. PFA the screenshot

    letter.png

    I have tried the below SQL. But it is not working

    INSERT INTO lettercopy (lid, alpha) SELECT letter.id as lid, letter.name as alpha FROM letter WHERE NOT EXISTS ( SELECT * FROM lettercopy WHERE lid = ( SELECT id FROM letter))

    Thanks
    Jans

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,408
    Mentioned
    149 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by codlib View Post
    I tried insert ignore but it is not working.
    Make lid PK.

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,021
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by codlib View Post
    ...it is not working.
    i'm sorry, i cannot guess

    would you please show the actual error message
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •